Can't work this one out for the life of me, hopefully I am not doing something stupid but why this is not working is not clear to me.
I have a basic HTML page with a JQuery script that sends the following AJAX call to a PHP script within the same directory.
JQuery:
// Sends the AJAX request
$.ajax({
type: "GET",
url: "process.php",
dataType: "json",
success: function(data) {
console.log(data);
}
});
PHP:
<!-- Ajax request handler -->
<?php
echo json_encode(array('message' => 'AJAX call received'));
exit();
?>
The AJAX call is being made successfully as after debugging it in the console it's status code is 200 and statusText 'ok'. However, I simply cannot get the returned JSON message to show up in the console as it should.
I have double checked the URL and that's fine.
This is the response I get in the console using Jeff Hatz's AJAX Debugger Chrome Extension:
Any ideas folks?
<!-- Ajax request handler -->before the json, then the ajax json parser will not work. You must only and truly return a pure json string from your php when usingdataType: 'json'.