Nick
Nick

Reputation: 7525

Poll the database from a web page? - ASP.NET

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?

Upvotes: 5

Views: 1514

Answers (4)

Michael Bray
Michael Bray

Reputation: 15265

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 browser will appear to continue "loading" the page until it finishes.

Upvotes: 0

Rodrick Chapman
Rodrick Chapman

Reputation: 5543

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

Upvotes: 4

RickNZ
RickNZ

Reputation: 18654

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.

Upvotes: 0

Burt
Burt

Reputation: 7758

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.

Upvotes: 0

Related Questions