JSONP Long polling always loading

I am doing a long survey using JSONP, and firefox constantly pops up using "Loading", which makes the page look like it didn’t finish loading. Is there any way to suppress this?

I was told that the Orbited team has hacks to suppress this, but looking at the Orbited.js code, I cannot understand what it is. Any help would be greatly appreciated.

+3
source share
2 answers

This is a simple fix. All you have to do is run your poll request using setTimeout ..

, . jQuery, , , , , .

<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>
+5

, . - .

, , Cross-Origin XMLHttpRequest JSONP .

( , ) CORS, , , .

+2

Source: https://habr.com/ru/post/1739362/


All Articles