JSONP长轮询始终加载 [英] JSONP Long Polling always loading

查看:141
本文介绍了JSONP长轮询始终加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSONP进行长轮询,并且firefox不断弹出正在加载"微调框,使页面似乎尚未完成加载.有没有办法抑制这种情况?

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?

有人告诉我Orbited团队有抑制这种情况的技巧,但是通过Orbited.js代码查看,我无法弄清楚它们是什么.任何帮助将不胜感激.

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.

推荐答案

这是一个简单的解决方法.您要做的就是以setTimeout启动轮询请求.

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

这是我使用的一些代码.它使用jQuery,但我认为您可以弄清楚您需要做什么,并使用您的库来做同样的事情.

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>

这篇关于JSONP长轮询始终加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆