ok i have this following code that parses JSON from an ajax response using $.parseJSON of jquery
try{
var indata = $.parseJSON(rsp);
}catch(err){
alert("an error occured");
}
Now as I want to cover any possible errors gracefully I tried to do some error handling which is usually try and catch now this code doesn’t work. I intentionally do some malformed JSON and pass it to the $.parseJSON but it doesn’t really work. Now my question is how I can handle this error gracefully
I would recommend handling errors in jquery ajax error callback. If you specify the
dataTypeas json, you should end up in theerrorcallback instead ofsuccessif the json string is not correctly formatted