如何把从服务器向浏览器新的HTML数据而无需刷新页面 [英] How to push new HTML data from the server to the browser without refreshing the page

查看:120
本文介绍了如何把从服务器向浏览器新的HTML数据而无需刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过很多网站(Facebook或堆栈溢出为例)的新数据生成(新的答案上一个职位为例),将更新的某些功能。

I have seen many websites (facebook or stack overflow for instance) that will update certain features as new data is generated (new answer on a post for example).

比方说,有一个新的职位加入到一个博客,有人在博客里的那一刻看着吧,DIEA是自动的新职位添加到博客无刷新或有用户做任何操作

Lets say that there is a new post added to a blog and someone is in the blog in that moment looking at it, the diea is to automatically add the new post to the blog without refreshing or having the user to do any action.

我本想执行一个AJAX调用每5秒左右,但是,这将使过多的对服务器的请求,我看到这些网站究竟是谁续约,没有要求作出的内容。

I have thought of executing an AJAX call every 5 seconds or so, but that will make too many requests to the server, and I have seen those websites who actually renew content that no request are made.

我是真的出了如何实现这个想法。这可能与PHP和AJAX,我听说过的WebSockets的,任何想法? 谢谢

I am really out of ideas of how to achieve this. Is this possible with PHP and AJAX, I've heard of websockets, any ideas? Thanks

推荐答案

大问题。有几个解决方案。

great question. There's a few solutions..

还有的是一个相对较新的解决方案,这一呼吁的WebSockets。这是在HTML5标准, 有它很多图书馆的其他语言了。

There's been a relatively new solution to this call websockets. It's in the HTML5 standard and there's a lot of libraries for it on other languages too.

其中之一是sockets.io(JavaScript)的 - 它使你保持一致,与服务器低延迟连接来接收,因为它是生成的信息。还有很多插件PHP,C,以及服务器端蟒。

One of them is sockets.io ( javascript ) - it enables you to keep a consistent, low-latency connection with a server to receive information as it's generated. There's also plenty of plugins for php, c, and python for the server side.

要仅举几例:libwebsockets(C ++),pywebsockets(蟒蛇)和码头(JavaScript的)

To name a few: libwebsockets ( c++ ), pywebsockets ( python ), and jetty ( javascript )

和PHP的: http://socketo.me/

请访问此链接了解更多信息: http://www.html5rocks.com/ EN /教程/的WebSockets /基础/

Visit this link for more info: http://www.html5rocks.com/en/tutorials/websockets/basics/

这篇关于如何把从服务器向浏览器新的HTML数据而无需刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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