有没有办法根据 beforeSend 结果终止 ajax 执行?
$.ajaxSetup({
beforeSend: check,
});
function check() {
if(success) { /* break ajax execution */ }
else { /* continue */ }
}
有没有办法根据 beforeSend 结果终止 ajax 执行?
$.ajaxSetup({
beforeSend: check,
});
function check() {
if(success) { /* break ajax execution */ }
else { /* continue */ }
}
我看到可以在这里找到答案:Stop $.ajax on beforeSend。它应该如下所示:
$.ajaxSetup({
beforeSend: check,
});
function check(xhr) {
if(success) { xhr.abort(); }
else { /* continue */ }
}
您可以尝试使用 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()
只需将它放在一个函数中:
$.ajax({
beforeSend: function() {
check();
},
});