Possible Duplicate:
Stop all active ajax requests in jQuery
I want to have a button that will abort any ajax requests currently being run. Below is a selector that grabs the right button. What should go in the place of the alert('test')?
$('#abort').click(function(){
alert('test')
});
You need to call abort() method - on each of the ajax calls !
var request = $.ajax({
type: 'POST',
url: 'someurl',
success: function(result){..........}
});
After that you can abort the request:
request.abort();
Create an array for each xhr object:
var xhrArray = new Array();
For every xhr object you need to add it to an array (where xhr is the object):
xhrArray.push(xhr);
Then on abort:
for( i = 0; i < xhrArray.length; i++){
xhrArray[i].abort();
stop = true;
}
The stop variable is for a loop that is elsewhere in my code to prevent more xhr objects from being created/sent.
精彩评论