开发者

Live updates using AJAX

I'd like to make a div's contents update as soon as a new row appears in a MySQL database (I'm making a webmail app). As I'm writing this, it's becoming more clear to me that I can't send some sort of server message to the client asking it to update, so I've come to the conclusion that the best way to have live updates is to use a jQuery ajax call, triggered by a setTimeOut event.

My question is: is there a better way to do this? Or if I have to use setTimeOut, what time interval should I set to keep the optimal balan开发者_JS百科ce between server usage and update times?

The code run every AJAX call will be one query (to fetch new mails) and a loop to post it to a ul.


This is the best way unless you use Stream Hub or a COMET server which is reverse AJAX :)


I think HTML5 WebSockets might be what you're looking for...

There's an example usage here.

As you mention, support is limited to Chrome and Safari at present.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜