John Davidson

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) => {
var messageData = new Object(); = document.getElementById('conname').value; = document.getElementById('conemail').value;
messageData.message = document.getElementById('conmessage').value;
messageData.verification = 'drovarcrete_message';
var messageString = JSON.stringify(messageData);

type: "POST",
contentType: 'application/json',
url: 'messageSender.php',
data: messageString,
dataType: 'json',
success: function(data) {
alert("Message send.");



$("#modal2_close").click(function() {

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


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