views:

47

answers:

4

Is there a way to abort all AJAX requests globally without a handle on the request object?

The reason I ask is that we have quite a complex application where we are running a number of different AJAX requests in the background by using setTimeOut(). If the user clicks a certain button we need to halt all ongoing requests.

+1  A: 

You need to call abort() method:

var request = $.ajax({
    type: 'POST',
    url: 'someurl',
    success: function(result){..........}
});

After that you can abort the request:

request.abort();

This way you need to create a variable for your ajax request and then you can use the abort method on that to abort the request any time.

Also have a look at:

Sarfraz
+1  A: 

This question may provide you with what you are looking for http://stackoverflow.com/questions/1802936/stop-all-active-ajax-requests-in-jquery

Barry
+1  A: 

You cannot abort all active Ajax requests if you are not tracking the handles to them.

But if you are tracking it, then yes you can do it, by looping through your handlers and calling .abort() on each one.

Roberto Sebestyen
+1  A: 

you can use this (use Ajax Queue plugin)

http://www.protofunc.com/scripts/jquery/ajaxManager3/

Haim Evgi