asp.net - 强制页面刷新

发布于 2024-10-21 00:35:44 字数 321 浏览 9 评论 0原文

我在拍卖网站上有一个倒计时,当有人在拍卖的最后两分钟内出价时,倒计时会重置为 2 分钟。这部分按其应有的方式工作。 我需要的是,当有人点击出价按钮时重新加载页面,以便其他人在操作计数器时看到计数器重置,而无需按 F5。

我尝试过不同的东西,比如刷新页面的元标记、带有计数器的 javascript 函数等...

但是,如果有人需要在出价后立即看到计数器刷新,则需要每次刷新页面其次,这很糟糕......

所以,我想,是否可以使用 ex. 在给定的时间间隔内重新加载页面。元标记,是否可以仅在触发某些事件时执行相同的操作?

有人有什么妙计吗?

谢谢

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 interval 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终遇你 2024-10-28 00:35:44

我要做的就是使用ajax。
像 jQuery 这样的库可以使这一切变得非常简单。
只需每隔几秒就拉动服务器一次,无需刷新。
如果计时器发生变化,您只需更新计时器,甚至无需刷新页面。

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.

我为君王 2024-10-28 00:35:44

如果您关心使用轮询模型生成服务器请求的频率,那么您也许可以研究基于 Comet(又名反向 Ajax、Ajax 推送)的解决方案。

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

简单地解释一下,您依赖于一种实现,在该实现中,您从页面向服务器发出单个 DoYouHaveAnUpdateEvent 请求,并在实际存在 UpdateEvent 之前避免响应该请求。收到 UpdateEvent 响应后,页面发出新的 DoYouHaveAnUpdateEvent 请求

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

一抹微笑 2024-10-28 00:35:44

如何使用 jquery每 10 秒向服务器进行一次 ajax 调用,以查看是否有任何其他出价...然后更新dom 元素 由时间组成...这样你就不必在任何地方刷新页面。

我会提到纯 JavaScript,但 jquery 会更容易,学习曲线更短,并且具有避免跨浏览器问题的能力。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文