jQuery .Ajax Error Handling Function

$(function() {
    $.ajaxSetup({
        error: function(jqXHR, exception) {
            if (jqXHR.status === 0) {
                alert('Not connect.
 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.
' + jqXHR.responseText);
            }
        }
    });
});

参考:

http://www.unseenrevolution.com/jquery-ajax-error-handling-function/

http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages

原文地址:https://www.cnblogs.com/miralce/p/4871778.html