Created
September 30, 2014 10:57
-
-
Save ethyde/bf55a4869b26e4d408a2 to your computer and use it in GitHub Desktop.
jQuery Ajax Error Handling Function.
Source: http://www.jquery4u.com/ajax/jquery-ajax-error-handling-function/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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