I have an HTML form which is correctly loaded into the DOM and displayed with the form coming into the DOM via a jQuery ajax call.
I submit the form data to a PHP module again jQuery ajax-called. From the network traffic I can see that the form data are being correctly sent to the called PHP module and that the called PHP module is echo-ing a text response, but the response is being displayed on a blank page and is not being returned to the calling script.
Can anyone please help me with what I am doing wrong?
jQuery 3.1.1 under Windows 7 and localhost/XAMPP/SSL.
I have tried lots of ajax submission approaches from SO but in each case the data are correctly sent to the called PHP module which in turn correctly echo's some text but in every case that echo'd text is displayed on a blank page.
/* attach a submit handler to the form */
$("#contact").submit(function(event)
{
/* stop form from submitting normally */
event.preventDefault();
/* get the action attribute from the <form action=""> element */
var $form = $(this),
url = $form.attr('action');
/* Send the data using post */
$.ajax({
url: url,
method: "POST",
data: {message:$('#message').val()}, // received as a $_POST array
dataType: text,
success: function(response)
{
alert(response);
}
}) <!-- end the ajax call -->
}) // end submit function*
In a nutshell, the success code never executes as the data are not being returned to it even though the called program is echoing what I expect.