开发者

Client ajax updates from the server without repeating code every second?

I would like to check a database for a c开发者_C百科hange 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


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/.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜