javascript 如何停止ajax请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9374305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to stop ajax request
提问by tsds
I'm using jquery for making ajax requests
我正在使用 jquery 进行 ajax 请求
$.ajax(
url: "http://someurl.org",
success: function() { ... }
);
How can I manually stop my particular ajax request?
如何手动停止我的特定 ajax 请求?
回答by Darin Dimitrov
The $.ajax()
method returns an object that could be used to do that:
该$.ajax()
方法返回一个可用于执行此操作的对象:
var xhr = $.ajax(
url: "http://someurl.org",
success: function() { ... }
);
and then later when you want to stop the request:
然后当你想停止请求时:
xhr.abort();
回答by JIA
ajax requests are HTTP transactions once made cannot be stopped. You can stop ajax request from being initiated but not kill the already made request.
ajax 请求是 HTTP 事务,一旦发出就无法停止。您可以停止发起 ajax 请求,但不能终止已发出的请求。