Posted by : Jebastin Wednesday, 19 February 2014

By using the $.ajaxSetup() we can handle the error/exception as mentioned below:
  1. $(function() {
  2.     $.ajaxSetup({
  3.         error: function(jqXHR, exception) {
  4.             if (jqXHR.status === 0) {
  5.                 alert('Not connect.\n Verify Network.');
  6.             } else if (jqXHR.status == 404) {
  7.                 alert('Requested page not found. [404]');
  8.             } else if (jqXHR.status == 500) {
  9.                 alert('Internal Server Error [500].');
  10.             } else if (exception === 'parsererror') {
  11.                 alert('Requested JSON parse failed.');
  12.             } else if (exception === 'timeout') {
  13.                 alert('Time out error.');
  14.             } else if (exception === 'abort') {
  15.                 alert('Ajax request aborted.');
  16.             } else {
  17.                 alert('Uncaught Error.\n' + jqXHR.responseText);
  18.             }
  19.         }
  20.     });
  21. });
Reference: StackOverflow.com

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Link To This Post/Page

Spread The Word

Add this button to your blog:
JJ Technology Solutions

Blog Archive

Trackers

eXTReMe Tracker
facebook

- Copyright © JJ Technology Solutions - Powered by Source Code Solutions -