簡體   English   中英

等到我所有的ajax函數都完成后,再繼續執行我使用過的async:false,但這與性能無關

[英]Wait until all my ajax functions are done, and then continue the execution for this i used async:false but it's not relative to performance

validateStepOneChannelData: function(callback)
    {
        var response = {error: false, data: {}};
        var error  = false;
        var action = $("#action").val();

        $.ajax({
        type: "POST",
        url: '/verifyEmailAddressByKickBox',
        dataType: "json",
        async:false,
        data: ({email: $("#email").val()}),
        beforeSend:function(){
            $('#next_box1_button').prop('disabled', true).addClass('hy-loading-btn');
            $('#saveChannel').prop('disabled', true).addClass('hy-loading-btn');
        },
        success: function(res) {
                $('#next_box1_button').prop('disabled', false).removeClass('hy-loading-btn');
                $('#saveChannel').prop('disabled', false).removeClass('hy-loading-btn');
                if (res.status == 'F') {
                    error = true;
                    response.data.email = 'Please enter valid email address.';
                }

            }
        });

        if (error)
        {
            response.error = true;
        }

        callback(response);

我需要等到我所有的ajax函數都完成后,再繼續執行我使用async:false的執行,但這與性能無關。 它凍結了瀏覽器,直到沒有ajax請求。

我們在這里如何使用回調首先獲取響應並執行其余的塊。

請指教。

我相信這種方式可以為您提供幫助

function ajaxCall(url,type,data = {}){

    return $.ajax({

        type:type,
        url:url,
        data:data

    })
}

 ajaxCall("url.php","post", {data:data} ).then(function(r){

    // something what you need to do after ajax

 })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM