ajax status为canceld

作者: admin 分类: javascript 发布时间: 2018-09-01 10:26

因为ajax请求太久,会出现canceled状态,然后尝试把ajax的timeout值设置为2000,发现ajax请求成功并返回数据。

You can attach an ajaxError handler to document

$(function(){
    $(document).ajaxError(function(event, request, settings) {
         //Do whatever
    });
});

Edit: To set Ajax timeout globally, you have to use ajaxSetup

$.ajaxSetup({
    timeout: 2000 //Time in milliseconds
});

Note:$.ajaxSetup should be set before other Ajax calls.