0

我试图在提交 ajax 调用之前显示一个微调器 FA 图标,并在 ajax 完成时显示一个正确/错误的 FA 图标,但这些图标仅在整个函数结束时才会更改。它在调试模式下完美运行,但仅在单击功能结束后才更改类。

$('#submitModal').click(function () {           
        for (var i = 0; i < arrInvoices.length; i++) {

            //wait(3000);  //1 seconds in milliseconds
            $.ajax({
                type: "POST",
                url: applicationBaseUrl + "/Home/GenerateActivity",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,                
                beforeSend: function () {
                    debugger;
                    addClassInModal(i, 'fas fa-spinner fa-pulse');

                },
                success: function (data) {
                    //alert(data);
                    debugger;

                },
                error: function (data) {
                    debugger;
                    //alert(data);
                },
                complete: function () {
                    debugger;
                    //wait(3000);  //1 seconds in milliseconds
                    if (i % 2 == 0) {
                        //success
                        //$("#List_Header_" + i).css({ "background": "green", "color": "white" });
                        $("#List_Icon_" + i).css({ "color": "green" });

                        //$("#List_Icon_" + i).removeClass('fa-spinner fa-pulse');
                        removeClassInModal(i, 'fa-spinner fa-pulse')

                        //$("#List_Icon_" + i).addClass('fa-check-circle');
                        addClassInModal(i, 'fa-check-circle')
                    }
                    else {                        
                        //error
                        //$("#List_Header_" + i).css({ "background": "red", "color": "white" });
                        $("#List_Icon_" + i).css({ "color": "red" });

                        //$("#List_Icon_" + i).removeClass('fa-spinner fa-pulse');
                        removeClassInModal(i, 'fa-spinner fa-pulse')
                        //$("#List_Icon_" + i).addClass('fa-times-circle');
                        addClassInModal(i, 'fa-times-circle')
                    }
                },               
            });

            //alert("out");

            reloadFlag = true;

        }
    });
4

0 回答 0