Cross-browser implementation of "HTTP Streaming" (push) AJAX pattern Cross-browser implementation of "HTTP Streaming" (push) AJAX pattern ajax ajax

Cross-browser implementation of "HTTP Streaming" (push) AJAX pattern


The solution you linked to is not AJAX at all, actually. They call it HTTP Streaming but it's essentially just long polling.

In the example they link to, you can see for yourself quite easily with firebug. Turn on the Net panel - there are no XHR entries, but it takes just a hair over 10 seconds to load the original page. That's because they're using PHP behind the scenes to delay the output of the HTML. This is the essence of long polling - the HTTP connection stays open, and the periodic HTML sent back is javascript commands.

You can opt to do the polling completely on the client side, though, with setTimeout() or setInterval()

A jQuery example

<script type="text/javascript">  $(document).ready(function()  {    var ajaxInterval = setInterval( function()    {      $.getJSON(        'some/servie/url.ext'        , { sample: "data" }        , function( response )          {            $('#output').append( response.whatever );                    }      );    }, 10000 );    });</script>


I would take a look at orbited

They use several comet transport implementation that they choose based on configuration and browser sniffing.

See http://orbited.org/svn/orbited/trunk/daemon/orbited/static/Orbited.js

and look for "Orbited.CometTransports"

Some of the different transports must be matched by the backend implementation, so have a look at the server side for orbited also.