<分区>
是否可以中止先前运行的 Ajax 请求?
var xhr = $.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
标签 javascript jquery ajax
<分区>
是否可以中止先前运行的 Ajax 请求?
var xhr = $.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
最佳答案
尝试这样的事情
$(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 );
}
});
}
});
关于javascript - 中止先前运行的 Ajax 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20159017/