简体   繁体   English

中止ajax调用javascript

[英]aborting ajax call javascript

I use the code below from one Stackoverflow answer to abort AJAX call in JavaScript/jQuery. 我使用下面的代码从一个Stackoverflow的答案中删除JavaScript / jQuery中的AJAX调用。

$.xhrPool.abortAll = function () {
  // alert('aborting.... outside');

  $(this).each(function (idx, jqXHR) {
    //jqXHR.abort();

    if (jqXHR && jqXHR.readyState != 4) {
        alert('aborting.... outside');
        jqXHR.abort();
    }
  });
  $.xhrPool.length = 0

  clearTimeout(timeoutOfCall);
  timeoutOfCall = null;
};

But, when I call this function like this : 但是,当我这样调用这个函数时:

$.xhrPool.abortAll();

it generate error in "unknown property" in IE 9 and also not working in Chrome. 它在IE 9中的“未知属性”中生成错误,也无法在Chrome中生效。 It is only working in FF. 它只在FF工作。

If your whant to stop specific ajax call and your jquery is 1.5.1 or newest your can use method "abort" of jqXHR object. 如果你想停止特定的ajax调用并且你的jquery是1.5.1或者最新的你可以使用jqXHR对象的方法“abort”。

var jqxhr = $.ajax(your ajax call);
jqxhr.abort();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM