Skip to content

Instantly share code, notes, and snippets.

@dyaa
Created September 22, 2013 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyaa/6659710 to your computer and use it in GitHub Desktop.
Save dyaa/6659710 to your computer and use it in GitHub Desktop.
JQUERY AJAX ERROR HANDLING FUNCTION
$(function() {
$.ajaxSetup({
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment