I am currently implementing some kind of HTTP Push using Long Polling for browsers that do not support ajax multicast responses.
I have to admit that although the server side is working fine, I relate to a new aspect of front-end javascript development and may have made some obvious mistakes
The problem is this: LongPolling works fine on IE 6,7,8 and Firefox (although Firefox uses multipart, I also tested it with a long poll), but Safari and Chrome make browsers “busy” during ajax requests. (they show a window's wait cursor, and Safari also shows a Download indicator in the title bar)
This, of course, is undesirable.
Here is my code to do a long survey based on jQuery 1.4.1:
function MepSubscribeToQueueLongPoll(name, callback) { var queueUrl = MepGetQueueUrl(name, "LongPoll"); MepLongPollStep(queueUrl, callback); }; function MepLongPollStep(url, callback) { $.ajax({ url: url, async: true, cache: false, success: function (data,status,request) { callback(request.responseText); MepLongPollStep(url, callback); } }); };
Please note that I bypass the jQuery data parsing functionality by passing request.responseText directly to the callback because Jquery does not seem to support ajax multiple response actions, and I wanted to be consistent along the exchange path.
jquery ajax
Gluber
source share