jQuery的服务器端推送与阿贾克斯服务器端、jQuery、阿贾克斯

2023-09-10 18:59:05 作者:玩一场没有结局的戏。

我在做一个社交网络的中间,我想这是一样光滑如Facebook。 如果你在一个控制台,看看日志一样,它不与Ajax调用更新所有的时间。

I am in the middle of making a social network, and i want it to be as smooth as facebook. Like if you look in a console and look at logging, it doesn't update all the time with ajax calls.

在我的网站我有负载:通知(新notifs数量和notifs本身),好友请求(与通知),在线好友(如果有任何在线将加载的在线用户的图片。 )这就是每一个被加载10秒6 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. and this causes a huge bandwidth waste and server requests.

所以我觉得,如果该服务器告诉客户端时,出现了一个新的更新,而不是客户端向服务器每隔10秒。

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.

我用Google搜索这个问题,并阅读有关Ajax推,和框架,叫做彗星。 我只是似乎无法找到如何实现这个jQuery的任何信息。

i have googled this problem and read about ajax push, and a framework called comet. i just can't seem to find any info on how to implement this on 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. The web already has several good texts on the subject.

就个人而言,我会坚持目前的计划(传统的AJAX),但做一个通用的调用了所有必要的数据捆绑成一个对象,JSON EN codeD。这将减少6请求向下一(每10秒)。

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. This will reduce 6 requests down to one (every 10 seconds).

您可以框,通过巧妙的信息返回的对象并没有改变,从而最大限度地减少每个响应的长度内返回空值。

You can box-clever by returning nulls within the returned object for information that hasn't changed thereby minimising the length of each response.