John Davidson

Unable to receive response from PHP to Ajax

0 comments
Message:


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.



My Answer:
> It looks like your code snippet is incomplete. Can you provide the rest of the JavaScript code that handles the AJAX request to the PHP script? This will help me understand the issue better and provide you with a more accurate solution.

Rate this post

3 of 5 based on 8588 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us