tags:

views:

131

answers:

4

Here's what I am trying to do. I have a website that lets users submit requests that are queued up in a Jobs table that the service picks up and processes. I have a status column in the table that denotes whether the request is queued up for processing or being currenty processed by the service or the service has completed processing the request. The entire process takes a few minutes.

I have a Status ASP.NET page in which I will need to show the current status of their request on a real time basis. I want to display some kind of animation and denote the current status. One way I could do this is to have a meta http refresh every x seconds that checks the status of the request (I guess this is how sites such as Expedia, Priceline does it?)

I would like to prevent a complete page refresh is possible and looking for a AJAX/JQuery solution. How would I implement this? Is polling the correct approach?

A: 

Polling is probably the best approach if you don't want the web page to run continuously on the server...

However, if that doesn't bother you, then you might want to take a look at a [similar answer] I gave to another question that allows you to dynamically update the page... The browswer will appear to continue "loading" the page until it finishes.

Michael Bray
+4  A: 

Polling via AJAX is the easiest and simplest for your needs. If you know the upper and lower bounds on the time it will take then I'd probably just have the animation run for that length of time and then do something for the exceptional case.

Others have done the same:

See: http://news.ycombinator.com/item?id=946165 and http://www.chrisharrison.net/projects/progressbars/ProgBarHarrison.pdf

Rodrick Chapman
can you elaborate or point me to a code sample on how to implement this?
For the polling solution see: http://buntin.org/2008/09/23/jquery-polling-plugin/ It's for a chat application but can *easily* be adapted for your needs.
Rodrick Chapman
A: 

Have you looked into Asynchronous calls to the server. This would allow you to put a call into the server and not wait for the result, when the call finished an event would be triggered an a method on the client page would be hit, this sounds like what you need and you wouldn;t have to do polling, here is more info:

http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

Hope this helps.

Burt
Wouldn't I run into timeouts if the process takes longer than the session timeout?
A: 

You might want to look into "long polling," also known as Comet.

The idea is that you make an async Ajax request from the client. On the server side, you pend the request until some status changes (so that it has something new to report). Then you release the request, and it returns the updated info.

This has an advantage over pure polling in that the requests only return when something has changed. It can also appear more responsive, since it's largely driven by the server side.

RickNZ