When running jQuery Ajax requests, you can catch server related code errors by using the statusCode object:
$.ajax({
url: 'script.php',
type: 'GET',
dataType: 'json',
statusCode: {
404: function() {
$("#response").html('Could not contact server.');
},
500: function() {
$("#response").html('A server-side error has occurred.');
}
},
error: function() {
$("#response").html('A problem has occurred.');
},
success: function() {
$("#response").html('Success!');
},
});
0 Comments