Jquery ajax error callback

后端 未结 6 1924
暖寄归人
暖寄归人 2020-11-28 09:08

I need some suggestions here or maybe some explanations. I have a jquery ajax call,

$.ajax({
 type: \"GET\",
 url: base_url+\'/ajax/fetch/counts/\',
 dataTyp         


        
6条回答
  •  天命终不由人
    2020-11-28 09:42

    Just an suggestion, try using the $.ajaxSetup() to get the correct error like this:

    $(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);
                }
            }
        });
    });
    

提交回复
热议问题