AJAX调用的实时进度(asp.net)
我正在尝试制作一个进度条,向用户更新 AJAX 调用的进度。
我立即想到的是,我需要一个 AJAX 调用来在服务器上启动一个线程,允许启动的 AJAX 调用完成,并允许该线程将更新发送回用户。
为了简单起见,忽略实际的进度条功能(我正在考虑实现其中一个 JS 条,具有精美的颜色和效果;),但如果我可以从线程获取更新,则更新一个简单的 JS 进度条变得微不足道;))
我只需要一些关于如何实现这一点的指示,如果有人可以帮助我吗? ;)
I'm trying to make a progress bar that updates the user on the progress of the AJAX call.
My immediate thinking was that I need an AJAX call to start a thread on the server, allowing the starting AJAX call to finish, and allowing the thread to send updates back to the user.
For the purpose of simplicity, disregard the actual progress bar functionality (I was thinking of implementing one of those JS bars, with fancy colors and effects ;), but if I can get an update from the thread, then updating a simple JS progress bar becomes trivial ;) )
I just need a few pointers on how to accomplish this, if anyone could oblige me? ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题的关键是从服务器获取已完成工作的百分比。唯一的出路是每 x 秒轮询一次服务器。有几种方法,
或
http://encosia. com/2007/07/25/display-data-updates-in-real-time-with-ajax/
或使用 jquery 进行轮询。
以“t”间隔轮询服务器并获取状态。为此,我们需要以“t”间隔调用一个函数,该函数将启动对 HTTPHandler 的 AJAX 调用以获取状态。
因此,您将有两个 httphandler,一个用于启动进程,另一个用于获取状态。
您可以研究这些并看看什么更适合您。
Crux of the problem is to get the % of work completed from the server. The only way out is to poll the server every x seconds. There are couple of approaches,
OR
http://encosia.com/2007/07/25/display-data-updates-in-real-time-with-ajax/
OR use jquery for polling.
Poll the server at 't' interval and get the status. For that we need to call a function at 't' interval that would initiate an AJAX call to a HTTPHandler to get the status.
So you will have two httphandlers, one to start the process other to get the status.
You can research on these and see what suits you better.