djacobs7
djacobs7

Reputation: 11827

polling the server with 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.

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

Upvotes: 5

Views: 1022

Answers (2)

karim79
karim79

Reputation: 342745

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
});

Upvotes: 4

Tom Studee
Tom Studee

Reputation: 10452

You could use a timer:

http://www.mcfedries.com/JavaScript/timer.asp

Upvotes: 0

Related Questions