简体   繁体   English

jQuery服务器端使用Ajax推送

[英]jQuery server side push with ajax

I am in the middle of making a social network, and i want it to be as smooth as facebook. 我正在建立一个社交网络,我希望它能像Facebook一样流畅。
Like if you look in a console and look at logging, it doesn't update all the time with ajax calls. 就像您在控制台中查看日志一样,它并不会一直通过ajax调用进行更新。

on my site i have to load: notifications(the number of new notifs and the notifs themselves), friend requests(same as notifications), online friends(if there are any online it will load the pictures of the online users.) thats 6 ajax calls that is loaded every 10 second. 在我的网站上,我必须加载:通知(新通知的数量和通知本身),朋友请求(与通知相同),在线朋友(如果有在线则将加载在线用户的图片。)多数民众赞成在6每10秒钟加载一次的ajax调用。 and this causes a huge bandwidth waste and server requests. 这会造成巨大的带宽浪费和服务器请求。

Therefore i thought, what if the SERVER told the CLIENT when there was a new update instead of the CLIENT asking the SERVER every 10 seconds. 因此,我想,如果SERVER告诉CLIENT何时有新更新,而不是CLIENT每10秒询问SERVER怎么办?

i have googled this problem and read about ajax push, and a framework called comet. 我已经用谷歌搜索了这个问题,并阅读了有关ajax push和一个称为Comet的框架的信息。 i just can't seem to find any info on how to implement this on jQuery. 我只是似乎找不到任何有关如何在jQuery上实现此信息。

I looked briefly into Comet. 我简短地看着彗星。 It appears to be ambitious, experimental and won't run on just any old server. 它似乎是雄心勃勃的,实验性的,不会在任何旧服务器上运行。

As I understand it, Comet doesn't really push as such but does something called "long polling", which I won't try to describe here. 据我了解,Comet并没有真正推动,但会执行称为“长时间轮询”的操作,在这里我不会尝试描述。 The web already has several good texts on the subject. 网络上已经有关于该主题的好文章。

Personally, I would stick with the current plan (conventional AJAX) but make one general purpose call with all the necessary data bundled into an object and JSON encoded. 就我个人而言,我会坚持当前的计划(传统的AJAX),但进行一次通用调用,将所有必需的数据打包到一个对象中并以JSON编码。 This will reduce 6 requests down to one (every 10 seconds). 这会将6个请求减少到一个(每10秒)。

You can box-clever by returning nulls within the returned object for information that hasn't changed thereby minimising the length of each response. 您可以通过在返回的对象内返回null来获取未更改的信息,从而使每个响应的长度最小化,从而实现盒式分割。

As far as I know, you must make significant modifications on your webserver to get this thing to work. 据我所知,您必须在Web服务器上进行重大修改才能使此功能正常工作。 Also, server side php is not really a good option. 另外,服务器端php并不是一个很好的选择。

Somebody had already asked something similar here: Using comet with PHP? 有人已经在这里问过类似的问题: 在PHP中使用Comet吗?

You can try socket.io on node.js too. 您也可以在node.js上尝试socket.io。 It works great for real time communication http://socket.io/ 它非常适合实时通信http://socket.io/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM