How do I use one method to terminate all ajax requests on this page? Abort An ajax object calls five ajax times and five ajax calls five abort times

  javascript, question

Can ajax of the whole page be terminated in one call?

var ajax1=$.ajax({});
var ajax2=$.ajax({});
var ajax3=$.ajax({});
var ajax4=$.ajax({});
var ajax5=$.ajax({});

To terminate these five ajax requests, I need to

Is there a method that can be called once


Because I now have to modify the entire project in such a large amount that I can only find a unified way to put it in the template page and use it on every page.

The specific method has already been mentioned by other respondents: put ajax objects into an array.

However, I estimate that the subject is now facing an existing project, and there are many changes and heavy workload in revising various parts. Then I offer a method with the smallest possible changes:


Specific code:

var ajaxs = [];
 var oldAjax = $.ajax;
 $.ajax = function() {
 var args =;
 var ajax = oldAjax.apply(this, args);
 return ajax;
 //add abortAll function.
 function abortAll() {
 $.each(ajaxs, function(i, ajax) {

In this way, there is no need to modify every call. When cancel, only need to adjustabortAll()Just do it.

For reference only.