小编典典

在beforeSend上停止$ .ajax

ajax

我有这个jQuery ajax调用:

$.ajax({
    url : 'my_action',
    dataType: 'script',
    beforeSend : function(){
        if(1 == 1) //just an example
        {
            return false
        }
    },
    complete: function(){
        console.log('DONE');
    }
});

我想beforeSend在条件返回的情况下停止ajax调用,true但返回false不会停止ajax调用。

我如何stop在Ajax上调用beforeSend?

=======更新=========

return false 也可以。


阅读 551

收藏
2020-07-26

共1个答案

小编典典

$.ajax({
url : ‘my_action’,
dataType: ‘script’,
beforeSend : function(xhr, opts){
if(1 == 1) //just an example
{
xhr.abort();
}
},
complete: function(){
console.log(‘DONE’);
}
});

2020-07-26