I use ajax to run MySQL query and echo json_encode result, so that I can get a JSON object:
$.ajax({
url: phpUrl,
data: command,
dataType: 'json',
async: true,
success: function(jsonData) {
//XXX
}
The JSON object should be like: {cols: [XXXX], rows: [XXXX]}.
Sometimes there is error msg from MySQL query, so the returned JSON object is not valid. How can I determine if the returned JSON object is valid or not?
edit
In http://api.jquery.com/jQuery.ajax/, it says “the JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown”. How to handle the parse error?
Something like this should work: