ajax取消重复请求

var pendingRequests = {};
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
var key = options.url;
if(!pendingRequests[key]) {
pendingRequests[key] = jqXHR;
} else {
//jqXHR.abort(); //放弃后触发的提交
//console.log('abort');
pendingRequests[key].abort(); // 放弃先触发的提交
}

var complete = options.complete;
options.complete = function(jqXHR, textStatus) {
pendingRequests[key] = null;
if($.isFunction(complete)) {
complete.apply(this, arguments);
}
};
});

posted @ 2017-08-23 15:49  ransom  阅读(464)  评论(0编辑  收藏  举报