Handling PHP exceptions with JQuery
- by Itamar Bar-Lev
Hello,
I'm using JQuery to call a PHP function that returns a JSON string upon success or throws some exceptions. Currently I'm calling jQuery.parseJSON() on the response and if it fails I assume the response contains an exception string.
$.ajax({
type: "POST",
url: "something.php",
success: function(response){
try {
var json = jQuery.parseJSON(response);
}
catch (e) {
alert(response);
return -1;
}
// ... do stuff with json
}
Can anyone suggest a more elegant way to catch the exception?
Many thanks,
Itamar