Html 自动刷新网页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/445458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:59:39  来源:igfitidea点击:

Auto refresh web page

htmldatabaserefresh

提问by Epitaph

I have a web page which allows the user to carry out various operations that in turn modify the database. Also, this web application needs to keep track of various fields in database that keep changing with time. Is refreshing the page every few seconds the best possible way to implement this? For example, if there is a long list on the page requiring scrolling, it is hard to view the list since the page keeps resetting due to the refresh. I know, there are ways to retain the position of the scroll. But, could I use something more efficient?

我有一个网页,它允许用户执行各种操作,进而修改数据库。此外,该 Web 应用程序需要跟踪数据库中随时间不断变化的各个字段。每隔几秒钟刷新一次页面是实现此功能的最佳方法吗?例如,如果页面上有一个长列表需要滚动,则由于刷新页面不断重置,因此很难查看列表。我知道,有一些方法可以保留滚动的位置。但是,我可以使用更有效的东西吗?

采纳答案by DonX

Use AJAX with timer.Using this we can refresh the particular part in the page.

使用带定时器的 AJAX。使用它我们可以刷新页面中的特定部分。

回答by Satya

Place it under head tag

把它放在头标签下

<meta http-equiv="refresh" content="5">

This will refresh page every after 5 seconds.

这将每 5 秒刷新一次页面。

For other option refer link text

对于其他选项,请参阅链接文本

回答by FAISAL

This task is very easy use following code in html header section

此任务很容易使用以下 html 标题部分中的代码

<head> <meta http-equiv="refresh" content="30" /> </head>

It will refresh your page after 30 seconds.

它会在 30 秒后刷新您的页面。

回答by Milhous

Short answer is NO. YOu can use ajax to update the necessary components. This reduces the load time and keeps your page from resetting.

简短的回答是否定的。您可以使用 ajax 来更新必要的组件。这会减少加载时间并防止您的页面重置。

回答by royalghost

I think you need something similar to Reverse AJAX now popularly known as Comet. It is server pushing the data to the client instead of browser polling the data from the server/database. http://en.wikipedia.org/wiki/Comet_(programming)has a good introduction. There are already many frameworks (e.g. DWR, ICEFaces) that support this pattern.

我认为您需要类似于现在普遍称为 Comet 的 Reverse AJAX 的东西。它是服务器将数据推送到客户端,而不是浏览器从服务器/数据库轮询数据。http://en.wikipedia.org/wiki/Comet_(programming)有很好的介绍。已经有很多框架(例如 DWR、ICEFaces)支持这种模式。

回答by Matthew

AJAX with a Timer

带定时器的 AJAX

回答by Christian Nunciato

Without going into too much detail, in general you might want to consider generating your HTML dynamically, using Javascript, in an Ajax-style manner. It's considerably more challenging to do right, but it's the right way to go from a user-experience perspective.

不涉及太多细节,一般而言,您可能需要考虑使用 Javascript 以 Ajax 样式的方式动态生成 HTML。正确行事更具挑战性,但从用户体验的角度来看,这是正确的方法。

Check out the Yahoo user-interface libraryfor guidance and assistance -- it does make things a good deal easier than trying to do everything by hand.

查看Yahoo 用户界面库以获得指导和帮助——它确实使事情比尝试手动完成所有事情要容易得多。

回答by Eng Sibo Dams

if you want to autorefresh the whole page,use meta html tag in the page header.but it better to autoresh the specified part of the page using AJAX to avoid the elasticity of loading time

如果要自动刷新整个页面,在页眉中使用meta html标签。但最好使用AJAX自动刷新页面的指定部分,以避免加载时间的弹性

回答by Spencer Ruport

That sounds like a functionality that would be better suited in a Flash or Silverlight application. Using an elaborate AJAX solution might be a bit more efficient than your but the reality is that web pages make a terrible medium for live content.

这听起来像是更适合 Flash 或 Silverlight 应用程序的功能。使用精心设计的 AJAX 解决方案可能比您的效率更高一些,但现实是网页为实时内容提供了一种糟糕的媒介。

回答by Massimiliano Ubicini

I think that the following is a good solution with the refresh command in the header.

我认为以下是标题中刷新命令的一个很好的解决方案。

When you call the httpSuccess function try to use this:

当您调用 httpSuccess 函数时,请尝试使用它:

server.httpSuccess("text/html","Refresh: 30\r\n");