停止$就在beforeSend [英] Stop $.ajax on beforeSend

查看:417
本文介绍了停止$就在beforeSend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个jQuery的AJAX调用:

  $。阿贾克斯({
    网址:my_action,
    数据类型:'脚本',
    beforeSend:函数(){
        如果(1 == 1)//只是一个例子
        {
            返回false
        }
    },
    完成:函数(){
        的console.log(完成);
    }
});
 

我想停止 beforeSend 如果条件返回在Ajax调用,但是返回false不会停止Ajax调用。

我怎样才能停止在AJAX调用 beforeSend

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

返回false 工作为好。

解决方案

  $。阿贾克斯({
    网址:my_action,
    数据类型:'脚本',
    beforeSend:功能(XHR,选择采用){
        如果(1 == 1)//只是一个例子
        {
            xhr.abort();
        }
    },
    完成:函数(){
        的console.log(完成);
    }
});
 

I have this jQuery ajax call:

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

I want to stop the ajax call under the beforeSend if the condition returns true but return false does not stop the ajax call.

How can I stop the ajax call on the beforeSend?

======= UPDATE =========

return false works as well.

解决方案

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

这篇关于停止$就在beforeSend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆