[英]How to kill the previous ajax request in server side?
我正在使用JQuery 1.9.1 。 這個問題可能是先前一些問題的重復,但是這些問題已經過時了,因此我需要一個最新的解決方案。
對於我的Java應用程序,我每10 sec
通過JQuery-Ajax
向tomcat server
發送一個連續請求,以獲取類似的數據,
function startPolling(){
$.ajax({
type: "POST",
cache: false,
url: "My URL",
dataType: "html",
timeout: 10000,
success: function(response) {
if(response != null && response !="" && response !="null")
$("#sucess").html(response);
},
error: function(xhr) {
xhr.abort();
//alert('Error: ' + e);
},
complete: function(xhr, status) {
xhr.abort();
startPolling();
},
});
}
請確保我以適當的方式abort/cancel
了client side
先前請求。
另外,如何通過ajax發送新請求之前中止server side request processing
。
希望我們的堆棧用戶能幫助我。
客戶端中有一個錯誤在這里中止
var pollXhr;
function startPolling(){
if(pollXhr){
pollXhr.abort()
}
pollXhr = $.ajax({
type: "POST",
cache: false,
url: "My URL",
dataType: "html",
timeout: 10000,
success: function(response) {
if(response != null && response !="" && response !="null")
$("#sucess").html(response);
},
complete: function(xhr, status) {
pollXhr = null;
startPolling();
},
});
}
注意:這不會停止服務器端處理
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.