> hello, > > I finally got my server to run an example comet application, which > uses the long polling method. > > The example code I got uses prototype library, which i dont want to > use. I understand there is a comet plugin for jquery that supports the > bayeux protocol, which is not what I want. > > Searching in this group, I have read that the long pollling method > does not require a plugin, and just the standard ajax methods are ok. > > What I need to do shortly, is to submit an ajax request, (which will > only be replied when the server sends data) when the server sends data > (it sends success in the body, and json data in the response header), > the ajax method must process the json data, and restart itself making > another ajax request. also, this ajax request should start at document > ready. > > Any ideas? > > Best, > -C.B.
This should get you started: (function($) { $(document).ready(startComet); function startComet() { $.ajax({ url: 'myCometServer.php', complete: onComplete }); }; function onComplete(xhr, status) { if (status == "success") { var json = xhr.getResponseHeader('myCometHeader'); $.globalEval('('+json+')'); startComet(); } else { // handle errors } }; })(jQuery);