Jquery同步ajax调用不更新UI

时间:2016-01-15 08:40:16

标签: javascript jquery ajax user-interface

我有一个同步的ajax调用,它在循环中执行。我试图在执行任何ajax调用之前更新UI,并在每个all的完成回调方法上更新UI.UI仅在完成所有ajax调用后更新。这是我的代码。

$("#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();

1 个答案:

答案 0 :(得分:0)

问题与您的异步消息有关:false 如果您做到了,那它将起作用