【问题标题】:Kendo Progress bar not initiating while making ajax call进行ajax调用时剑道进度条未启动
【发布时间】:2016-02-25 12:51:47
【问题描述】:

我想为我的服务器端 ajax 调用实现 Kendo 进度条。 我试过了,但它没有在 ajax 调用之前启动,如果我使用下面的 setTimeOut 函数来关闭 ajax 调用,进度条只会显示很短的时间。 例如:

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

在上面的代码中,进度条只显示 5000 毫秒,然后关闭。这是我的实际要求。

我需要两个 ajax 调用,一个在另一个内部。我想在第一个 ajax 调用启动之前实现进度条,并希望在第二个 ajax 调用完成后关闭。 另一种选择是在第一次 ajax 调用启动之前实现进度条,并在第一次调用完成后关闭它,然后为第二次 ajax 调用启动进度条,并在第二次 ajax 调用完成时关闭。

我希望我的要求很明确。如果您需要更多详细信息,请告诉我。这是我的代码:

 <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>

提前谢谢...

【问题讨论】:

    标签: javascript jquery ajax kendo-ui kendo-progressbar


    【解决方案1】:

    这里有几件事。
    1. Kendo 依赖于 JQuery,但您试图在 JQuery 处理程序初始化之前初始化进度小部件。始终将 Kendo 代码放在 JQuery 处理程序中,并确保在您的 Kendo 脚本之前包含对 JQuery 库的引用。

    <script>
    $(function ()
    {
        kendo.ui.progress($("#progressBar"), true);
    
        // Make your ajax call here
    }
    

    2。确保您的放置代码关闭每个可能的代码路径中的进度条,否则它将无限期地运行并且您的用户将无法继续。在您的示例中,您在第二次调用的 Complete 处理程序中有 kendo.ui.progress($("#progressBar"), false,但不是第一次。如果用户在第一次调用时遇到错误,则永远不会关闭进度条。

    3. 你在代码中禁用了异步模式,但你的评论让我觉得你不是故意的。 async:false 在这里不是必需的,因为您在第一次成功的情况下进行了第二次 AJAX 调用。通过这种方式,您可以自己控制调用的执行顺序。

    4. 我想你已经知道了,但是在任何类型的进度指示器上设置一个预定义的超时值并不是一个好主意,因为你无法知道这个过程需要多长时间。

    【讨论】:

    • 非常感谢。现在我清楚我做错了什么。
    • 我试过了,但它也不起作用。实际上 jQuery 我正在初始化 jQuery 。请查看上面的完整代码。我编辑了之前的代码。请根据需要对上述代码进行任何更改或提出任何其他建议。
    • 在这里我想添加..根据你这里的第三点异步:需要 false。否则我们无法通过服务调用获取数据。如果还有其他的请给我建议。
    • 那么到底发生了什么?进度条开始了吗?
    • 进度条未启动。如果是调试模式,则显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多