Auto Refresh a page in Rails 3

和自甴很熟 提交于 2019-12-04 23:50:43

问题


How to periodically auto refresh page with paramaters in Rails 3?


回答1:


Place the following HTML within the <head> of the applicable views. This should not be used when the page had POST parameters sent, only GET parameters. Change the 5 to the interval, in seconds, you want the page to refresh at.

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

Though this works, I'd recommend considering using AJAX to refresh only the needed content which will not only be faster but less jolting to the user and will have a lower impact on your server's load.

This is not specific to Rails and applies to any webpage. Since Rails is server-side, and the server cannot control the browser, Rails has no control over page refreshing.




回答2:


A completely different and more modern approach is to use a service such as PusherApp. It will open a socket to the Pusher server in Javascript and listen for events that should generate changes on your page.

http://pusherapp.com/docs/quickstart



来源:https://stackoverflow.com/questions/5100469/auto-refresh-a-page-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!