2011-07-15 37 views

回答

0

看一看this blog post,它解釋了XMLHTTPRequest.Abort()方法。我相信這就是你要找的。

2
var xhr = null; 

xhr = $.ajax({ 
    url : 'www.example.com?some-large-call', 
    success : function(responseText) { 
     // some DOM manipulation 
    } 
}); 

$("#cancel").click(function() { xhr.abort() }); 

這應該爲你工作

+0

我使用.ajaxForm jquery插件。我不知道如何訪問xhr對象。 –

0

最壞的情況下,你可以嘗試這樣的事情

var isRequestCancelled = false; 

isRequestCancelled = false; 

$.post({ url:"", success:function{ 
    if(isRequestCancelled){ 
    //Alert the user with cancel message 
    } 
    else{ 
    //Confirm the user 
    } 
} 
}); 

//Show a cancel buttons once you post to server and on cancel click set the global variable. 

$(".cancel").click(function(){ isRequestCancelled = true;}); 
+0

會不會繼續「POST」? – beardhatcode

+0

是的。正如我所說的,即使在發佈成功後用戶取消了它,也是處理最糟糕的情況。 – ShankarSangoli

+0

這確實是最糟糕的情況,因爲在某些情況下,您需要向服務器發送「撤消」 – beardhatcode

相關問題