Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!