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 dataType
as json, you should end up in the error
callback instead of success
if the json string is not correctly formatted
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With