Requested JSON parse failed
27,170
Solution 1
data: { json: order } ... it's not well formatted...
Solution 2
There is no parsing error in this JavaScript code.
Please post the response of "index.php" and the error message you got.
Have a look at the response data. Open index.php in the browser, press F12 and insert this into the console:
$.ajax({
type: "POST",
url: "index.php",
//dataType: "json",
data: { json: order },
success: function(data) {
console.log(data);
}
});
Author by
holyredbeard
Updated on July 05, 2022Comments
-
holyredbeard almost 2 years
By some reason there's a parsing error with the ajax code below. How could I find out what it is, and/or can someone see what's wrong?
$('#listElements').sortable({ //revert: true, update: function(event, ui) { var order = []; $('.listObject li').each(function (e) { order.push($(this).attr('id')); }); $.ajax({ type: "POST", url: "index.php?", dataType: "json", data: { json: order }, error: function(jqXHR, exception) { if (jqXHR.status === 0) { alert('Not connect.\n Verify Network.'); } else if (jqXHR.status == 404) { alert('Requested page not found. [404]'); } else if (jqXHR.status == 500) { alert('Internal Server Error [500].'); } else if (exception === 'parsererror') { alert('Requested JSON parse failed.'); } else if (exception === 'timeout') { alert('Time out error.'); } else if (exception === 'abort') { alert('Ajax request aborted.'); } else { alert('Uncaught Error.\n' + jqXHR.responseText); } } }); }