开发者

asp.net - Force page refresh

开发者 https://www.devze.com 2023-02-16 04:34 出处:网络
I have a countdown on an auction site, that resets to 2 minutes when someone places a bid within the last two minutes of the auction. This part works as it should.

I have a countdown on an auction site, that resets to 2 minutes when someone places a bid within the last two minutes of the auction. This part works as it should. What I need, is to reload the page when someone hits the bid-button, so that someone else wathing the counter, sees the counter reset, without hitting F5.

I've tried different things, like a meta tag that refreshes the page, javascript functions with counters, etc...

However, if someone needs to see the counter refresh immediately after a bid has been placed, the page needs to be refreshed every second, and that sucks...

So, I figured, if it is possible to have the page reload at a given interva开发者_运维技巧l using ex. a meta tag, would it be possible to do the same only when some event is fired?

Anyone with some tricks up their sleeves?

Thnx


What I would do is use ajax. A library like jQuery can make this very simple. Just pole the server every few seconds without a refresh. If the timer changes, you just update the timer without even refreshing the page.


If you are concerned with the frequency with which you will be generating server requests using a polling model, then you could perhaps look into a Comet (a.k.a. Reverse Ajax, Ajax push) based solution.

http://en.wikipedia.org/wiki/Comet_%28programming%29

Simply explained you rely on an implementation where you fire a single DoYouHaveAnUpdateEvent request from the page to the server and simply avoid responding to the request until there is actually an UpdateEvent. Upon receiving the UpdateEvent response, the page issues a new DoYouHaveAnUpdateEvent request


How bout using jquery to make an ajax call to server every 10 seconds to see if any other bid has been placed...then update just the dom element which consists of the time...that way u dont have to refresh the page anywhere.

I would have mentioned plain javascript but jquery would be easier with a lesser learning curve and added ability of avoiding cross browser issues.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号