简体   繁体   English

ajax调用之前进度条没有显示?

[英]progress bar not showing before ajax call?

I want to implement the progress bar before the first ajax call initiating and want to close once the 1st call over getting over and then again i want initiate the progress bar for 2nd ajax call and want to close when the 2nd ajax call getting complete. 我想在第一个ajax调用启动之前实现进度条,并想在第一个ajax调用结束后关闭一次,然后再次想启动第二个ajax调用的进度条,并想在第二个ajax调用完成时关闭。

I tried but it's not showing. 我试过了,但是没有显示。 It's calling and same time it's closing because of ajax call and i here i don't know the exact time ajax call and i can't use setTimeOut also for closing. 由于ajax调用,它正在通话,同时关闭。我在这里我不知道ajax调用的确切时间,也无法使用setTimeOut进行关闭。

here is the code. 这是代码。 please help me anyone to achieve this. 请帮助我实现这一目标。

var getResponseFromSOA = function(filterObject, file,verb, callback) {      
        createFilterString(filterObject, function(filterString) {// get the filter string
            if(jQuery) {// check the jQuery file is integrated or not
                var headers = {Authorization: COOKIES.readCookie("Authorization"),requestmode:"ACK_URL"};
                headers.isRender = file.isRender;
                if(file.inputDataHeaders)
                    headers.inputData = file.inputDataHeaders;


            // Here i want to show be ajax call
                  $progressBar.kendoProgressBarShow();


                    jQuery.ajax({
                        url: file.fileUrl + "/" + $securityComponent.cryptograghicFunctions.encryptor(filterString),
                        type: verb,
                        headers: headers,
                        async: false,
                    /*  beforeSend: function() {
                             $progressBar.kendoProgressBarShow();
                        },*/
                        error : function()
                        {
                            console.log("some error occured at getResponseFromSOA submitting the request");
                        },
                        success: function(responseDataFromRequestHandler) {                         
                            console.log(responseDataFromRequestHandler);                            
                            // again call because it is async mode form SOA team
                            jQuery.ajax({
                                url: responseDataFromRequestHandler.links[1].href,
                                async: false,
                                headers: {Authorization: COOKIES.readCookie("Authorization"),requestmode:"ACK_URL"},
                                success: function(responseDataFromResponseHandler) {
                                    try {
                                        console.log(responseDataFromResponseHandler);
                                        if(callback) callback(responseDataFromResponseHandler.data);

                                    }catch(e) {
                                        console.log(responseDataFromResponseHandler);
                                        // printing the error message in the console window
                                        console.log("Error in the callback in data-transactor-js > getResponseFromSOA"
                                                + "\n"
                                                + e.message);
                                    }
                                },                          
                                complete: function() {                               
                                     // Here i want to close the progressBar or last below it's commented mode
                                    $progressBar.kendoProgressBarHide();

                                }
                            });
                        },
                        complete: function() {                          
                             // Here i want to close the progressBar    or last below it's commented mode
                            $progressBar.kendoProgressBarHide();
                        }
                    });
                     // If it's not possible there then i want to close here.
                        //$progressBar.kendoProgressBarHide();


            } else throw {message: "jQuery is not defined or jQuery file is not linked"};
        });
    };

Here is Porgress API code. 这是Porgress API代码。

$progressBar = {    
    kendoProgressBarShow : function() {
        if (jQuery) {
            kendo.ui.progress($("#progressBar"), true);
        } else {
            console.log("jQuery not found");
        }
    },
    kendoProgressBarHide : function() {
        if (jQuery) {
            kendo.ui.progress($("#progressBar"), false);
        } else {
            console.log("jQuery not found");
        }
    }
};

Progress bar is not showing when a ajax call is made and async: false 进行ajax调用并async: false时,进度条不显示async: false

UI freeze UI冻结

Hence try setting async: true 因此,尝试设置async: true

or you can find the solution in below link 或者您可以在下面的链接中找到解决方案

https://codesave.wordpress.com/2013/09/25/ajax-call-freezes-ui-animation-locked-ui-during-ajax-call/ https://codesave.wordpress.com/2013/09/25/ajax-call-freezes-ui-animation-locked-ui-during-ajax-call/

You can try this type of logic in your program. 您可以在程序中尝试这种类型的逻辑。

$('#clickfun').click(function() {
    $(this).after('<div id="loading">Loading...</div>');
    for(var i=0;i<5;i++){


    setTimeout(function() {
        $.ajax({
            url: '/echo/html/',
            type: 'post',
            async: false,
            data: {
                html: '<p>Hello Friends</p>'+i,

            },
            success: function(data) {
                console.log(data);
                $('#clickfun').after(data + i);
            },
            error: function() {
                alert('Error found');
            },
            complete: function() {
                $('#loading').remove();
            }
        });
    }, 0);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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