1

I use the code below from one Stackoverflow answer to abort AJAX call in JavaScript/jQuery.

$.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. It is only working in FF.

Adinia
  • 3,722
  • 5
  • 40
  • 58
Naresh Parmar
  • 462
  • 3
  • 16
  • possible duplicate of [Abort Ajax requests using jQuery](http://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery) – jrummell Mar 11 '13 at 13:08

1 Answers1

3

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.

var jqxhr = $.ajax(your ajax call);
jqxhr.abort();
Vasily Komarov
  • 1,405
  • 9
  • 11
  • Ya, 'abort()' will stop client (browser) listening to a response from server. Problem is that it won't stop the server itself to generate the response's request. A other way will be to resend request to tell server to stop to handle previous request. That's make a extra call to server wich is most of time not necessary. It's really depends of which kind of previous request was made... – A. Wolff Oct 17 '12 at 10:36
  • no, i want to stop all the call which are pending and created with setinterval function. i am working on one GPS system app. so, i want to update device info on map after every 30 sec. so, when i change the device, all the ajax call pending for previous device should be aborted. – Naresh Parmar Oct 17 '12 at 10:43
  • Oh, so i misunderstand your question. – Vasily Komarov Oct 17 '12 at 10:43
  • Hi Vasily, will this code work only with 1.5.1 jquery version ?? not supported with higher version like 1.7.1,1.8.1 ??? – Naresh Parmar Oct 17 '12 at 11:03
  • hi all, it's working now. i had added 2 var like : var xhrPool = []; $.xhrPool = []; i just removed "var xhrPool = [];" this one, and it is working now. thanks for your time and help. – Naresh Parmar Oct 17 '12 at 12:36