[英]How to interrupt reponse function on jQuery AJAX?
I have an Ajax function which takes some time to respond, due to large file. 由于文件较大,我有一个Ajax函数需要一些时间来响应。 How do I interrupt the response function if I want to stop the Ajax request?
如果要停止Ajax请求,如何中断响应功能?
$("#startAjaxButton").click(function(){
$.ajax({
url:"ajaxRequest.txt",
success:function(result){
$("#div1").html(result);
}
});
});
Just use the abort()
method. 只需使用
abort()
方法即可。
Like this: 像这样:
var query = $.ajax({ ... });
// later...
query.abort();
You can stop the ajax request by using the .abort()
, 您可以使用
.abort()
停止ajax请求,
var xRequest = $.ajax({
url:"ajaxRequest.txt",
success:function(result){
$("#div1").html(result);
}
});
xRequest.abort();
There are two ways to stop the ajax request. 有两种方法可以停止ajax请求。 Either you can use the
abort()
method like following 您可以像下面这样使用
abort()
方法
var xhr = jQuery.ajax({
url : "/test",
...
});
xhr.abort();
Or using the timeout
option like following, 或者使用如下所示的
timeout
选项,
- var xhr = jQuery.ajax({
timeout : 3000,
...
}
Also you can refer the following links, which are similar to this question 您也可以参考以下链接,类似于此问题
abort-ajax-requests-using-jquery 使用jQuery中止ajax请求
How-to-Abort-a-AJAX-Call-Before-Calling-the-Same-A 如何在调用相同A之前中止AJAX调用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.