1

I am trying to implement a simple "comet" ajax long-polling mechanism (as described here).

The problem is, I cannot figure out how to tell the browser to act as if it has finished loading the page, although it has a pending request running in the background. (The l

One way is using web sockets, but that's way much of an overkill.

Ron Reiter
  • 3,852
  • 3
  • 30
  • 34

3 Answers3

1

Ah, the old "throbber of doom" :-)

There's another question about this which is probably worth a read. It refers to IFRAMEs but it's most probably still relevant.

I wrote up a post on the throbber while I was working on Kwwika but I came to the unfortunate conclusion that's it's not very easy to 100% get rid of it.

I'd suggest that WebSockets aren't actually overkill. Comet using XMLHttpRequest etc. isn't a standard fundamentally supported by web browsers. In other words they don't go out of their way to make creating long-lived HTTP requests super-easy. WebSockets are a standardised approach that are slowly but surly becoming supported in all browsers. I'm hoping that they make it into IE10. For now you can look at something like web-socket-js which will ensure WebSocket support in 99% of browsers. WebSockets also offer lower latency and are less resource-intensive that any kind of polling solution.

Community
  • 1
  • 1
leggetter
  • 15,248
  • 1
  • 55
  • 61
  • Thanks. what technology does web based chat use today? which techniques do facebook and gmail use? – Ron Reiter Aug 24 '11 at 18:18
  • 1
    I can't 100% guarantee what they use but from using the Network tab in Chrome whilst on Facebook it looks like they use HTTP long-polling. They make a call to channel URL such as `http://0.113.channel.facebook.com/x/2913703439/3177502653/true/p_684921145=0` and hold that connection open. Gmail appears to used plain old polling and make a call to a `channel/bind` url. People that use the technology of the company I work for, [Pusher](http://pusher.com), to build realtime chat, interactive or collaborative apps use [WebSockets](http://pusher.com/websockets) because it's what we use. – leggetter Aug 24 '11 at 23:13
0

You need async call to ajax http://api.jquery.com/jQuery.ajax/

hungryMind
  • 6,931
  • 4
  • 29
  • 45
0

OK, I've sorta managed to solve this. The problem of the "throbber of doom" was caused because I executed the ajax request under the document.ready function like this:

$(function() {$.ajax ... });

This solved it:

$(function() { setTimeout(connect, 1000); });

Ron Reiter
  • 3,852
  • 3
  • 30
  • 34