解決前端一次提交操作,后端接收多次请求

解决思路:

1、在每次请求前阻止ajax可能存在的多次重复请求

function prevent_reloading(){
var pendingRequests = {};
jQuery.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
var key = options.url;
console.log(key);
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);
}
};
});
}

2、引用定义的阻止函数

function xxxxx(){

 prevent_reloading();//阻止函数

  $.ajax({

    //真正要执行的方法

  })

}

参考:https://blog.csdn.net/qq_26870933/article/details/84991630

原文地址:https://www.cnblogs.com/memoa/p/10734351.html