【问题标题】:Jquery progress bar server sidejquery进度条服务端
【发布时间】:2014-08-27 19:15:16
【问题描述】:

我在服务器端(在 db 中运行多个查询)有一个长时间运行的进程(不是确定的时间),需要 30 多秒。我想以 % 的形式向用户显示进度。我在我的应用程序中使用 jquery ,struts 。 有办法吗?

【问题讨论】:

标签: jquery ajax jquery-ui struts2 struts2-jquery


【解决方案1】:

我们就是这样做的。

  • 当进程被触发时,从客户端创建一个 GUID 并将其传递给服务器。
  • 在服务器端,运行进程并在运行期间,使用 GUID 作为键将进度保存在会话/缓存中。
  • 在客户端,定期对传递 GUID 值的服务进行 ajax 调用。该服务将返回与 GUID 值对应的进度状态。
  • 根据从服务返回的值更新 ProgressBar 状态。
  • 如果您将值存储在会话中,一旦该过程完成,请确保清除它。

以下是进行 ajax 调用的示例方法。

    function updateProgress() {
        if (stopProgressCheck) return;
        var webMethod = progressServiceURL + "/GetProgress";
        var parameters = "{'guid':'" + guid + "'}"; //passing the guid value

        $.ajax({
            type: "POST",
            url: webMethod,
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d != "NONE") { //add any necessary checks
                    //add code to update progress bar status using value in msg.d
                    statusTimerID = setTimeout(updateProgress, 100); //set time interval as required
                }
            },
            error: function (x, t, m) {
                alert(m);
            }
       });    
    }

希望这对你有用:)

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多