Using the following code i am trying to send JSON data via javascript to a PHP script
Watching "isRunning" while stepping through the code returns true, ie suggests AJAX isn't running, however once the code progresses to the next portion of AJAX code "isRunning" changes to false;
I have tried to trap the error on the second portion - which returns "Unexpected error"
Does anyone have an suggestions as to what i am doing wrong, or how I can trap a more informative error response ?
var isRunning = true;
$.ajax({
url: url,
success: function(resp) {
isRunning = false;
}
});
jsonString = JSON.stringify(row);
$.ajax({
type: 'POST',
dataType: 'json',
url: 'email_rma.php',
data: {
json: jsonString
},
success: function(data) {
console.log('The answer from the PHP file: ' + data);
},
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
console.log('Internal error: ' + jqXHR.responseText);
} else {
console.log('Unexpected error.');
}
}
});
Thank you
Thanks to everyone or their suggestions, I think the issue lies with the JSON.stringify conversion, also i noticed i didn't include the PHP side, which i have kept to a minimum basically
$data = json_decode($_POST['json']);
echo "Data:-".$data."<BR>";
Is it possible that the problem lies on the PHP side ?
isRunning
variable to change right away, it's asynchronous, meaning it runs in parallel while the code you are stepping through is happening. It might change at any later point. – JNF Oct 26 '14 at 8:08email_rma.php
in your browser? Are you positive thejson_decode
is working? What version of PHP are you running? In the event of a failure to decode, json_last_error() can be used to determine the exact nature of the error. – JNF Oct 26 '14 at 18:20