Reputation: 101473
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 balance 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
.
Upvotes: 2
Views: 1740
Reputation: 97555
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.
Upvotes: 1
Reputation: 37454
This is the best way unless you use Stream Hub or a COMET server which is reverse AJAX :)
Upvotes: 2