Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Unable to receive response from PHP to Ajax

This is my absolute first try on the subject: I'm sending data throw email using javascript and PHP. I have read previous responses on the subject, but I can't make it work. My js code:

const messagesend = document.getElementById('message_form');
 messagesend.addEventListener('submit', (eee) => {
     eee.preventDefault();
     var messageData = new Object();
     messageData.name = document.getElementById('conname').value;
     messageData.email = document.getElementById('conemail').value;
     messageData.message = document.getElementById('conmessage').value;
     messageData.verification = 'drovarcrete_message';
     var messageString = JSON.stringify(messageData);
 
     $.ajax({
         type: "POST",
         contentType: 'application/json',
         url: 'messageSender.php',
         data: messageString,
         dataType: 'json',
         success: function(data) {
              alert("Message send.");
              $('#contactModal').modal('hide');
              $('#email_success_info').modal('show');
            
         }
     });

 });

 $("#modal2_close").click(function() {
     $('#email_success_info').modal('hide');
 });

My PHP works fine, with last line being: echo 'Message send'; I have also tried: echo json_encode(array('success' => true));

However, the alert message doesn't show.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Use the following and see what is going on with your request:

$.ajax({
    type: "POST",
    contentType: 'application/json',
    url: 'messageSender.php',
    data: messageString,
    dataType: 'json',
    success: function(data) {
        alert("Message send.");
        $('#contactModal').modal('hide');
        $('#email_success_info').modal('show');
    },
    error: function (error) {
        console.log(error.responseText);
    }
 });
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda