简体   繁体   English

进行Ajax调用时Kendo进度栏未启动

[英]Kendo Progress bar not initiating while making ajax call

I want to implement the Kendo progress bar for my server side ajax call. 我想为我的服务器端ajax调用实现Kendo进度栏。 I tried but it's not initiating before the ajax call, and if I use the setTimeOut function below for closing the ajax call, the progress bar only displays for a short duration. 我试过了,但是在ajax调用之前没有启动,如果我使用下面的setTimeOut函数关闭ajax调用,进度条只会显示很短的时间。 For example: 例如:

 setTimeout ( function() 
       {
        kendo.ui.progress($("#progressBar"), false); //close the progress bar       
       },5000);

In the above code, the progress bar only shows for 5000 milliseconds, after which it closes. 在上面的代码中,进度条仅显示5000毫秒,然后关闭。 Here is my actual requirement. 这是我的实际要求。

I need to have two ajax calls, one inside another. 我需要两个ajax调用,一个在另一个内部。 I want to implement the progress bar before the first ajax call initiates and want to close after the 2nd ajax call completes. 我想在第一个ajax调用启动之前实现进度条,并想在第二个ajax调用完成之后关闭。 Another option would be to implement the progress bar before the first ajax call initiates and close it once the 1st call is complete, then initiate the progress bar for the 2nd ajax call and close when the 2nd ajax call is complete. 另一种选择是在第一个ajax调用启动之前实现进度条,并在第一个调用完成后将其关闭,然后为第二个ajax调用启动进度条,并在第二个ajax调用完成时关闭。

I hope my requirement is clear. 希望我的要求明确。 If you need more details please let me know. 如果您需要更多详细信息,请告诉我。 Here is my code: 这是我的代码:

 <div id="progressBar"></div>

   <script> 
        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;
            /*
             * Since it is async call that's why call will be 2 times.
             * 1st time we have to call to the request handler of the SOA.
             * In the response we will get one link address of response handler.
             * 2nd time we have to call that link what we got from the 1st request.
             * Response handler will give actual data in the data property of the response
             */

                    kendo.ui.progress($("#progressBar"), true); //Here progress bar will initiate

                jQuery.ajax({
                    url: file.fileUrl + "/" + $securityComponent.cryptograghicFunctions.encryptor(filterString),
                    type: verb,
                    headers: headers,
                    async: false,
                    error : function()
                    {
                        console.log("some error occured at getResponseFromSOA submitting the request");
                    },
                    success: function(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() {

                                    kendo.ui.progress($("#progressBar"), false); //close the progress bar       

                            }
                        });
                    },
                    complete: function() {                          
                            kendo.ui.progress($("#progressBar"), false); //close the progress bar       

                    }
                });


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

</script>

Thanks in advance... 提前致谢...

A few things here. 这里有几件事。
1. Kendo relies on JQuery but you're trying to initialize the progress widget before the JQuery handler initializes. 1. Kendo依赖JQuery,但是您正在尝试在JQuery处理程序初始化之前初始化进度小部件。 Always place Kendo code inside the JQuery handler, and be sure to include the reference to JQuery library before your Kendo scripts. 始终将Kendo代码放在JQuery处理程序中,并确保在Kendo脚本之前包含对JQuery库的引用。

<script>
$(function ()
{
    kendo.ui.progress($("#progressBar"), true);

    // Make your ajax call here
}

2. Make sure your put code to turn off the progress bar in every possible code path or it will run indefinitely and your users won't be able to proceed. 2.确保放置代码以关闭所有可能的代码路径中的进度条,否则它将无限期运行,并且用户将无法继续。 In your example, you have kendo.ui.progress($("#progressBar"), false in the Complete handler for the second call, but not the first. If the user were to get an error on the first call, the progress bar would never be turned off. 在您的示例中,您有kendo.ui.progress($("#progressBar"), false在第二次调用(而不是第一次调用kendo.ui.progress($("#progressBar"), false的Complete处理程序中为kendo.ui.progress($("#progressBar"), false 。如果用户在第一次调用时遇到错误,则进度酒吧将永远不会被关闭。

3. You're disabling async mode here in code, but your comment makes me think you don't mean to. 3.您在此处的代码中禁用了异步模式,但是您的评论让我觉得您不是故意的。 async:false isn't necessary here since you are making the 2nd AJAX call in the success of the first. async:false在这里不是必需的,因为您将在第一次成功执行第二次AJAX调用时。 In doing it this way, you control the execution order of the calls yourself. 通过这种方式,您可以自己控制调用的执行顺序。

4. I think you know this already, but setting a pre-defined timeout value on any kind of progress indicator isn't a good idea, because you have no way of knowing just how long that process will take. 4.我想您已经知道这一点,但是在任何类型的进度指示器上设置预定义的超时值并不是一个好主意,因为您无法知道该过程将花费多长时间。

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

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