Javascript – AJAX constantly look for server update? Javascript

ajaxiphonejavascriptjquery

I have a situation where a display on a webpage needs to be updated at random. I am wanting to do this in AJAX but am not sure how to do this other than to do a

while(true) { ajaxFunction(); sleep(1) }

Type thing.

The problem with this is that the webpage needs to be updated very quickly on a change to the server, but the changes could happen very sporadically sometimes never.

EDIT: This is an Iphone application using a UIWebView, is it possible to use the iPhone's push notification to interface with the javascript?

Thanks!

Best Answer

I think what you're describing is Comet and there are a couple of plugins for jQuery:

http://code.google.com/p/jquerycomet/

http://plugins.jquery.com/project/Comet