- Back to Home »
- Ajax , jQuery »
Posted by : Jebastin
Wednesday, 19 February 2014
By using the $.ajaxSetup() we can handle the error/exception as mentioned below:
- $(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);
- }
- }
- });
- });