jquery ajax防止重复提交优化版

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

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

posted @ 2016-12-12 14:25  Forward1990  阅读(1084)  评论(0编辑  收藏  举报