Search code examples
cometlong-pollingorbited

JSONP Long Polling always loading


I'm doing long-polling with JSONP and firefox continually pops up the "Loading" spinner making the page seem like it hasn't finished loading. Is there a way to suppress this?

I've been told that the Orbited team has hacks for suppressing this, but looking through the Orbited.js code I cannot figure out what they are. Any help would be greatly appreciated.


Solution

  • This is a simple fix.. All you have to do is start your polling request with a setTimeout..

    Here is some code I use.. It uses jQuery, but I assume you can figure out what you need to and use your library to do the same.

    <script type="text/javascript">
      function poll(){
        $.getJSON('/updates', function(json){
          //reconnect since we successfully received data and disconnected
          poll();
    
          //add something here to do whatever with the recieved data
        });
      }
      /*call the poll function after document has loaded with setTimeout
      if called before the document finishes loading completely it will
      cause a constant loading indication*/
      setTimeout(poll, 1);
    </script>