开发者

Telling jQuery to reload page when there is a server side event

I have a page with a div and the elements within the div get updated from the server side periodically. For 开发者_运维百科example, I have a progress bar in it. Currently, I'm doing jQuery.load using setInterval to periodically refresh the div on the page (every 3 seconds). I was wondering if I could achieve this using an event-based method rather than a timer-based. For instance, I could have a server event fire everytime the progress changes, and I could then increase the width of the progress bar on the page (and change other elements as well). Question is how can I tell jQuery to do a load when this happens? Is there a jquery onchange event or somethign that watches for page changes?


Polling could be done, but there are a better way: Comet servers. Basically the HTTP server allows long running requests which means that it do not send the response unless something have happened or the timeout is about to kick in.

Read about comet here: http://en.wikipedia.org/wiki/Comet_(programming))

A comet plugin for jquery: http://plugins.jquery.com/project/Comet

A more technical article: http://ajaxpatterns.org/HTTP_Streaming


This is simply not possible because the underlying communication protocol (HTTP) between server & client is request-response based. So it is not possible for server to notify client w/o client making request for it. In short, polling is the way to go.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜