解决思路:

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

相关文章:

  • 2021-09-30
  • 2021-03-25
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
相关资源
相似解决方案