jquery的ajax我使用beforeSend返回了false为什么ajax还会继续提交?

function qrcodePay() {
var obj = {
money: getInputValue('zhenmoeny')
};

$.ajax({
    url: ctx + '/money/weiPengScanQrcode',
    type: 'post',
    contentType: 'application/json;charset=UTF-8',
    data:JSON.stringify(obj),
    aysnc: false,
    beforeSend: checkWaitRecord,
    success: function (data) {
    window.location.href = ctxWap + '/bb/aa?url='+encodeURIComponent(data);
        /*console.log(data);*/
    },
    error: function(){
        layer.closeAll();
        layer.msg("充值失败");
    }
});

}

function checkWaitRecord(XMLHttpRequest){
var flag;
$.ajax({
url: ctx + '/money/cc',
type: 'POST',
data: {},
async: false,
success: function (data) {
if(data == "1"){
console.log("不存在支付账单:" + data);
flag = true;
}else{
console.log("以存在支付账单:" + data);
var alert = confirm("是否继续上笔支付?不继续可能无法继续新的充值");
if(alert == true){
window.location.href = ctxWap + '/money/wechatPay?url='+encodeURIComponent(data);
}
flag = false;
}
}
});
return flag;
}

你在使用beforSend时请求是已经发起了,return 对这个已发起的请求是没有作用的。
推荐你使用promise.then()处理异步请求问题。把第二个请求放到then下面。如果第一个不成功 则不去请求第二个

beforeSend不是发送请求之前的意思,而是请求返回数据之前所做的操作。beforeSend无论返回什么,请求都已经发生了。

兄弟,你要知道$.ajax 是异步执行的,这个代码会瞬间执行完毕,然后另外一个线程会等待返回结果,这样主线程才不会卡死掉的。 而你在beforSend中又使用了$.ajax去验证,flag就会一直为false,因为beforSend瞬间就执行过去了。 具体的你百度了解下什么是 JQuery Ajax异步

别听他们瞎说,我试了一下如果beforeSend返回了false是不会继续执行的,

$.ajax({
        cache: false,//让IE不去读缓存,
        url:url,
        async:true,
        type:"post",
        data: postData,
        contentType: "application/json",
        success:function(response)
          {
                alert(response)
                cbk(response);
          },
          error: function (jqXHR, textStatus, errorThrown) {
                /*错误信息处理*/
                //  alert(jqXHR.responseText+"\n"+textStatus+"\n"+errorThrown);
            }
        }

这个ajax是异步吧,beforeSend返回false,就不会继续执行了