jQuery进度条服务器端 [英] Jquery progress bar server side
本文介绍了jQuery进度条服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在服务器端运行一个较长的过程(没有确定的时间)(在db中运行查询数量),耗时超过30秒.我想以百分比向用户显示进度.我在我的应用程序中使用jquery,struts. 有办法吗?
I have a long running process(not definite time) in server-side(which runs number of queries in db) which takes more than 30s. I want to display the progress in % to the user. I'm using jquery ,struts in my application. Is there a way to do it?
推荐答案
我们就是这样做的.
- 触发该过程后,请从客户端创建一个GUID并将其传递给服务器.
- 在服务器端,运行该过程,并在运行过程中,始终使用GUID作为键将进度存储在会话/缓存中.
- 在客户端,定期对通过GUID值的服务进行ajax调用.该服务将返回与GUID值相对应的进度状态.
- 基于从服务返回的值,更新ProgressBar状态.
- 如果您将值存储在会话中,则在过程完成后,请确保将其清除.
下面是进行ajax调用的示例方法.
Below is a sample method to make ajax calls.
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);
}
});
}
希望这对您有用:)
这篇关于jQuery进度条服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文