开发者

How do I set the “all ajax stop” function for multiple ajax requests?

开发者 https://www.devze.com 2023-02-06 09:01 出处:网络
xhr = $.ajax; xhr({ success: fun开发者_JAVA技巧ction(){ ajaxProcess = false; }, beforeSend : function (i) {
xhr = $.ajax;
xhr({
  success: fun开发者_JAVA技巧ction(){ ajaxProcess = false; },
  beforeSend : function (i) {
    if(ajaxProcess==true)
    xhr.abort();
    else
    ajaxProcess = true;
  }
});

$('.button').click(function(){
  $.getJSON('file.php', function(data){});
};

$('.button2').click(function(){
  $.getJSON('file.php', function(data){});
};


Use the global ajaxSend handler http://api.jquery.com/ajaxSend/

EDIT

To stop all executing requests, you can do something like the following. Create an array of request objects. Then in the the global ajaxSend handler you can add the request to the array and do your check. If the check succeeds, iterate through the array and abort all of the requests. Then you can create a global ajaxStop handler that removes the requests from the request array as they finish executing.

0

精彩评论

暂无评论...
验证码 换一张
取 消