Abort a previous running Ajax request
本问题已经有最佳答案,请猛点这里访问。
是否可以中止以前运行的Ajax请求?
1 2 3 4 5 6 7 8 | var xhr = $.ajax({ type:"POST", url:"some.php", data:"name=John&location=Boston", success: function(msg){ alert("Data Saved:" + msg ); } }); |
试试这个
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | $(document).ready(function(){ var xhr; // global object function your_function() { if(xhr && xhr.readystate != 4){ xhr.abort(); } xhr = $.ajax({ type:"POST", url:"some.php", data:"name=John&location=Boston", success: function(msg){ alert("Data Saved:" + msg ); } }); } }); |