tags:

views:

45

answers:

2

I would like to check a database for a change using ajax. However, I do not want to overload the server by constantly checking it every second.

Is there any other way of updating the clients from the server? Can jquery listen for event server side?

Thanks

+4  A: 

You could use long-polling. Basically you send a request to the server, and it waits to return with a response. The server will hold the connection until data is available, and it will then return the response containing the data.

For examples of long-polling with Javascript (frameworks), see this question. Additionally, PerplexedLabs did a short tutorial/example of long polling with jQuery and PHP earlier in 2009. You can view it online at http://blog.perplexedlabs...javascript-long-polling/.

Jonathan Sampson
I'm just guessing that is having AJAX call a script, and having the script `sleep()` if there is no data?
Chacha102
A useful search term is `comet`. See here: http://en.wikipedia.org/wiki/Comet_%28programming%29
RedFilter
A: 

Without Flash that is currently not possible. In the future WebSockets will make it possible. Using Flash you can set up a socket connection to the server.

Marius