当新用户上线自动刷新 [英] Auto refresh when new user comes online

查看:148
本文介绍了当新用户上线自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中包括所有活跃用户数据库中的表。然后,我有哪些需要刷新,看看谁是最新的用户在线用户列表。 请告诉我最好的方式来解决呢? 用户列表永远只是谁在ACTIVE_USERS表。 感谢您的阅读。

I have a table in the database which includes all active users. I then have a user list which needs refreshing to see who is the latest users online. Whats the best way to tackle this? The user list is always just who is in the active_users table. Thanks for reading.

推荐答案

您可以使用 AJAX 请求定期拉活跃用户的列表,并在网站上显示出来。

AJAX

You could use an AJAX request to pull regularly the list of active users and display them on your website.

您可能需要为缓存该列表的一小会儿的您的服务器上如果你有大量的用户请求它不断。

You may want to cache that list for a little while on your server in case you have a lot of users requesting it constantly.

或者,如果列表很长,或者如果你决定要拉很多HTML标记与列表中,你也可以定期查询你的服务器以检查是否有更新的(缓存...)列表自从上次在客户端更新列表。应答将是一个简单的真或假,而客户端将只需要请求新的列表时,它已经改变了。

Or, if the list is long, or if you decide to pull a lot of HTML markup with the list, you could also regularly poll your server to check whether there are updates to the (cached...) list since the last time the client updated the list. The reply will be a simple true or false, and the client will only have to request the new list when it has changed.

您也可以使用 元刷新标记 ,无论是更新整个页面,或者一个iframe,如果你不介意的内置页框。

You could also use the meta refresh tag, either to update the entire page, or an iframe if you don't mind iframes.

刷新后一分钟:

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

或用网址:

<meta http-equiv="refresh" content="60;url=http://site.com/list.php?counter=1" />


手动更新

最后,你可能只需要添加一个按钮或只是一个链接在列表的末尾,用户可以决定自己是否要重新加载与否。


Manual update

Finally, you may just add a button or a simply a link at the end of the list, and the user could decide for herself whether to reload or not.

由于 JoeGeeky 指出,在评论中,对于性能和带宽原因,您可能要实现一个计数器,它限制了倍加载用户列表的最大数。这是适用于Ajax和元刷新标记。在JavaScript中,你可以简单地具有可变递增每次加载列表,并在情况下,元刷新标记,你可以在URL中添加计数器作为GET变量的时间。

As JoeGeeky pointed out in the comments, for performance and bandwidth reasons, you may want to implement a counter which limits the maximum number of times the user list is loaded. This is valid for Ajax and Meta refresh tags. In javascript you could simply have a variable incrementing every time you load the list, and in case of the meta refresh tag you could add the counter in the url as a get variable.

另外那三个办法并不相互排斥,但应结合:使用的阿贾克斯的为乡亲用JavaScript激活时,元刷新的iframe 的在脚本标记作为后备的那些时禁用了javascript(所提到的 stagas ),和一个按钮或链接的手动更新的一次最大列表刷新数已经达到了。

Also those three approaches do not exclude each other but should be combined: Use Ajax for the folks with javascript activated, a meta refresh iframe in a noscript tag as a fallback for the ones with javascript disabled (as mentioned by stagas), and a button or link for manual update once the maximum list reload count has been reached.

这篇关于当新用户上线自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆