javascript - WebSocket如何向指定页面推送

WBOY
Release: 2016-06-06 20:14:56
Original
1243 people have browsed it

已经把PHP的WebSocket框架Demo跑起来了(workerman -> web-msg-sender)

现在遇到个问题,就是如何像指定页面推送信息。

比如每个用户的首页,和每个用户的收藏列表页,和一些公共的商品列表页,这些页面价格都是实时更新的。

<code>目前我想到的方法是:
1、当商品价格被执行更新后,从表中取出对应的商品信息
2、公共页:如首页,商品列表页;后台指定推送URL为这些页面,推送刚刚更新的商品ID和价格。JS获取后判断当前页面是否存在推送的商品ID,如果存在就更新价格?
3、个人页面,如收藏页也是这样处理么?</code>
Copy after login
Copy after login

回复内容:

已经把PHP的WebSocket框架Demo跑起来了(workerman -> web-msg-sender)

现在遇到个问题,就是如何像指定页面推送信息。

比如每个用户的首页,和每个用户的收藏列表页,和一些公共的商品列表页,这些页面价格都是实时更新的。

<code>目前我想到的方法是:
1、当商品价格被执行更新后,从表中取出对应的商品信息
2、公共页:如首页,商品列表页;后台指定推送URL为这些页面,推送刚刚更新的商品ID和价格。JS获取后判断当前页面是否存在推送的商品ID,如果存在就更新价格?
3、个人页面,如收藏页也是这样处理么?</code>
Copy after login
Copy after login

应该没有这种功能吧。通常的用法是浏览器端通过js的socket.io连接然后获取推送内容而已,是不是需要处理是由浏览器端的js决定的哦。比如说服务端推过来了{action: update; type: product; details:[{product_id:1, price: 5.30}]},浏览器端可以if ($('#product-list').length) updateProducts(response);就行了。
补充:上面说的有点绕嘴,简单说就是不需要处理,因为访问者既然不在特定的页面上,自然根本不需要去处理推送,如果处在特定的页面上,那么必然有特定的方法来处理,对不?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!