简体   繁体   中英

Jquery syncronous ajax call not updating UI

I have a syncronous ajax call which gets executed in a loop. I am trying to update the UI before any ajax call is executed and on the done call back method of each all.The UI is only updated after all ajax calls are made. Here is my code.

$("#warning").text("Do not close this screen!");
    setTimeout(function () { console.log("delay before ajax call") }, 4000);

    var strVale = document.getElementById('CompanyList').value;
    arr = strVale.split(',');
    LoadingPanel.Show();
    for (i = 0; i < arr.length; i++)
    {

        var d = new Date();
        var date = [pad(d.getDate()), pad(d.getMonth() + 1), d.getFullYear()].join('/');
        var time = [pad(d.getHours()), pad(d.getMinutes())].join(':');

        $("#" + arr[i]).text("Started at " + date + " " + time);
        $("#" + arr[i]).css('background-color', 'orange');

        $.ajax({
            type: "GET",
            async: false,
            contentType: "'application/json; charset=utf-8'",
            url: "/url?companyID=" + parseInt(arr[i]),                
        }).done(function (response) {
            // console.log(response);
            if (response.Success) {
                $("#" + response.CompanyID).css('background-color', 'lightgreen');
            }
            else {
                $("#" + response.CompanyID).css('background-color', 'lightpink');
            }

            $("#" + response.CompanyID).text(response.StatusMessage);
        });


    }

    LoadingPanel.Hide();

问题出在您的async上:如果为true,则为false,它将起作用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM