轮询服务器与AJAX [英] polling the server with ajax

查看:107
本文介绍了轮询服务器与AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个网站,有一个系统,用户可以将消息发送给对方。我想这样,当一个登录的用户接收到的消息,他会得到他的屏幕上的一些更新告诉他。

I am building a website that has a system where users can send messages to each other. I would like it so that when a logged in user received a message, he would get some update on his screen telling him that.

这些消息并不必须是实时的,所以我不认为我想要把彗星或者剑圣之类的东西。相反,我会很高兴,只是轮询服务器每分钟左右,然后等待更新。

These messages do not have to be in realtime, so I do not think I want to push with comet or juggernaut or anything like that. Instead, I would be happy to just poll the server every minute or so and listen for updates.

我是新来的JavaScript,我想知道如果有一个漂亮的/正确的方式来做到这一点。

I am new to javascript, and I am wondering if there is a slick/right way to do this.

推荐答案

原型有一个 periodicalUpdater ,这将是我认为的不二之选。记录在案的例子:

Prototype has a periodicalUpdater, which would be the obvious choice in my opinion. Documented example:

new Ajax.PeriodicalUpdater('items', '/items', {
  method: 'get', frequency: 3, decay: 2
});

这篇关于轮询服务器与AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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