我有一個jQuery ajax後,我用POST上傳大文件。我想給用戶在提交進行時取消提交,點擊按鈕的能力。我怎樣才能做到這一點 ?我應該如何阻止「正在進行中」的jquery POST?
回答
看一看this blog post,它解釋了XMLHTTPRequest.Abort()方法。我相信這就是你要找的。
var xhr = null;
xhr = $.ajax({
url : 'www.example.com?some-large-call',
success : function(responseText) {
// some DOM manipulation
}
});
$("#cancel").click(function() { xhr.abort() });
這應該爲你工作
我使用.ajaxForm jquery插件。我不知道如何訪問xhr對象。 –
最壞的情況下,你可以嘗試這樣的事情
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;});
會不會繼續「POST」? – beardhatcode
是的。正如我所說的,即使在發佈成功後用戶取消了它,也是處理最糟糕的情況。 – ShankarSangoli
這確實是最糟糕的情況,因爲在某些情況下,您需要向服務器發送「撤消」 – beardhatcode
- 1. 如果有交易正在進行,我該如何避免阻止選擇?
- 2. 是否應該阻止HTTP POST?
- 3. 如何防止$ window.location.href阻止正在進行的請求?
- 4. Jquery live()點擊正在製作uploadify的多個實例,我該如何阻止它進行上傳
- 5. 如何阻止我的應用程序進行連續處理
- 6. Safari正在緩存本地內容 - 我該如何阻止?
- 7. 如何阻止在jQuery的
- 8. 如果存在元素,我該如何阻止JavaScript執行?
- 9. 我該如何阻止特定的ruby守護進程?
- 10. 我應該如何阻止我的桌子在底部留下空白空間?
- 11. 我該如何阻止聲音?
- 12. 我該如何阻止「IndexOutOfBoundsException」問題?
- 13. 我該如何使用.htaccess阻止Bot。
- 14. 我如何在rails中進行POST?
- 15. 我們如何通過Windows cmd阻止正在運行的java進程?
- 16. 我應該阻止HTTP 1.0請求嗎?
- 17. 我應該阻止未來 - 斯卡拉
- 18. 阻止進程正在計劃中
- 19. 如何停止在jQuery $ .post?
- 20. 在CloudFlare中,如何阻止它阻止我的tumblr博客?
- 21. 我如何阻止阻擋?
- 22. 如何阻止我的應用在平板電腦上運行?
- 23. 我應該如何阻止長時間運行的WF4工作流程?
- 24. 我正在製作phonegap應用程序,iframe自動在safari中打開 - 我該如何阻止?
- 25. 我應該如何阻止垃圾郵件機器人?
- 26. 我該如何停止正在運行的水平進度條並重置它
- 27. 我該如何避免阻止在PHP Tidy中移除標籤?
- 28. 在URL中自動替換字符串,我該如何阻止?
- 29. 如何在Android中阻止(true)阻止
- 30. 我如何知道什麼時候正在創建進程並阻止其在Windows中執行或終止它?
您可以使用此: http://stackoverflow.com/questions/1802936/stop-all-active-ajax-requests-in-jquery –