views:

57

answers:

3

I'm wanting to create a shoutbox, though I'm wondering if there is another way to go about this rather than using setInterval to query the database for new shouts every number of seconds. Honestly, I don't like having to go about it this way. Seems a bit redundant and repetitive and just plain old wrong. Not to mention the blinking of the shouts as it grabs the data.

So I'm wondering on how the professionals do this? I mean, I've seen shoutboxes that work surperb and doesn't seem to be using any setInterval or setTimeout javascript functions to do this.

Can anyone suggest any ideas or an approach to this that doesn't use setInterval or setTimeout??

Thanks :)

A: 

Maybe you can use COMET?

HTML5 will allow having web sockets with javascript which will make this even better, but I would not use HTML 5 for that yet, until more people move to browsers which support it.

Francisco Soto
A: 

Instead of using timers, put a refresh button, let users manually update the messages, cbox do like that.

S.Mark
Yeah, but I need the users to be able to see the shouts as they occur, but only as they occur, not every so many seconds...
SoLoGHoST
+1  A: 

Use javascript to update the shoutbox as people write messages without reloading the whole page. Take a look at the code behind this shoutbox as an example. (Download link is on the right.) There are many other examples of shoutbox that use Javascript to seamlessly pull new "shouts" from the database all over the internet. Many of them are highly customizable so you can change the CSS to achieve whatever styling you want.

Here are a couple more examples of such scripts:
http://www.ajaxdaddy.com/demo-jquery-shoutbox.html
http://www.truefusion.org/TFsBOX/ (Code located here: http://code.google.com/p/tfsbox/ )

Oren
Thanks, I'm currently considering one of these options. I appreciate this.
SoLoGHoST