有没有办法根据beforeSend结果终止ajax执行?
$.ajaxSetup({
beforeSend: check,
});
function check() {
if(success) { /* break ajax execution */ }
else { /* continue */ }
}
答案 0 :(得分:2)
我看到答案可以在这里找到:Stop $.ajax on beforeSend。它应该如下所示:
$.ajaxSetup({
beforeSend: check,
});
function check(xhr) {
if(success) { xhr.abort(); }
else { /* continue */ }
}
答案 1 :(得分:0)
您可以尝试使用abort()方法:
var xhr = $.ajax({
type: "POST",
url: "test",
data: "thedata",
success: function(msg){ alert( "Back again: " + msg ); } });
//kill the request... try these on beforeSend
xhr.abort()
答案 2 :(得分:-1)
将它放在一个函数中:
$.ajax({
beforeSend: function() {
check();
},
});