绕过Ajax请求,但请继续脚本进入成功声明



有没有办法绕过运行中的ajax请求,但是仍然将脚本保留在成功语句中?我的条件是对还是错。如果是错误的,则应绕过AJAX请求。但是我仍然希望脚本在嵌套的成功函数中继续。因此,我无法使用此代码...

beforeSend : function(xhr, opts){
    if(bypass_ajax == 1) {
        xhr.abort();
    }
},

这是我要运行的代码...

   var bypass_ajax = true;
    $.ajax( {
        url: destination_url,
        data: { a:a, b:b },
        type: 'POST',
        success: function ( e ) {
            if( bypass_ajax == true ) {
                alert( 'Ajax request was manually bypassed, yet you can still read me...' );
            }
        }
    });

no。如果您中止了请求,则不会成功。

重构代码,因此您具有可重复使用的功能。

function success() {
    // success function
}
if (bypass_ajax) {
    success();
} else {
    $.ajax(...).done(success);
}

相关内容

最新更新