且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 jQuery 中停止所有活动的 ajax 请求

更新时间:2022-06-22 07:09:30

每次创建 ajax 请求时都可以使用变量来存储它:

Every time you create an ajax request you could use a variable to store it:

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

然后你可以中止请求:

request.abort();

您可以使用一个数组来跟踪所有待处理的 ajax 请求并在必要时中止它们.

You could use an array keeping track of all pending ajax requests and abort them if necessary.