如何将新的岗位和评论拉如何将、岗位

2023-09-10 21:25:18 作者:是王者不是亡者 ﹌

我目前正在开发一个网站,许多网友发帖主题和相关议题的意见将显示在页面上。目前,我正在开发使用的蛋糕PHP。

I am currently developing a website where many users post topics and the associated topics' comments are shown in the page. Currently I'm developing using cake php.

在第一次用户点击网站,所有的主题和注释显示。但是,当其他用户添加新的主题或注释的话题,我需要显示在同一页面更新。我很困惑,在我怎么能够检索新的内容,并在页面中相应地更新。比如如何Facebook并就在那里,当你的朋友加上你的身份地位或意见,它更新而无需刷新页面。

The very first time a user clicks the website, all the topics and comments are displayed. But when other users add new topic or comment to a topic, I need to show the update in the same page. I am confused as in how am I able to retrieve new contents and update accordingly in a page. For instance how facebook does it where when your friends adds status or comments on your status, it updates without refreshing the page.

我知道,AJAX技术的使用,但它是如何做的。我可以将任何来源?希望有人能帮助我一直在做研究的过去一个星期,但没有答案为止。

I know that AJAX technology is used but how is it done. Any source that I can refer? Hope someone can help as I have been doing research for the past one week but no answers so far.

推荐答案

您可以在这两条路线。

You can go two routes in this.

服务器推送

http://en.wikipedia.org/wiki/Push_technology

此技术可能是最有效的作为服务器通知任何更新客户端。但是这种技术通常需要比一个简单的投票系统,更多的工作。您可以使用类似 nodejs 或的彗星来推送更新。如果你使用nodejs,我强烈建议使用 SocketIO 来处理客户端。与Socket.io可以具有在客户端监听到服务器上的一个信道,以便服务器可以通知客户机每当更新发生。

This technique is perhaps the most efficient as the server notifies the client of any updates. However this technique usually requires a bit more work than a simple polling system. You can use something like nodejs or Comet to push updates. If you're using nodejs, I highly recommend using SocketIO to handle the client side. With Socket.io you can have the client side listening to the server on a channel so that the server can notify the client whenever an update happens.

客户端轮询服务器

在这个版本中,客户端(新访问者的浏览器)不断地轮询服务器进行更新。您可以设置任何缝隙你想要的,但请记住,如果你做的轮询间隔太小,你的服务器可能会采取的性能损失,因为每个新用户将产生很多的要求。这个方法很简单,只要建立在一个JS 的setInterval()通话再加上一个AJAX调用。

In this version, the client (new visitors browser) constantly polls the server for updates. You can set whatever gap you want, but keep in mind that if you make the polling gap too small your server might take a performance hit as each new user will create many requests. This method is as simple as setting up a setInterval() call in JS coupled with an AJAX call.