jsonp comet 挂起请求导致丑陋的“加载”浏览器上的状态

发布于 2024-09-24 11:52:21 字数 338 浏览 1 评论 0原文

我正在使用 jsonp 进行跨域 comet 请求,“正在加载”状态确实很烦人。

有什么方法可以用javascript抑制这种情况吗?

对于那些不熟悉 jsonp 的人来说,它基本上会注入一个脚本标记,但在我的情况下,我将请求挂在我的服务器上,直到稍后才返回请求。

在此期间,浏览器将我的请求视为“正在加载”状态。

我正在使用这个: http://code.google.com/p/jquery-jsonp/ !

提前致谢

I'm using jsonp to do cross-domain comet requests, and the "loading" status is really annoying.

Is there any way to suppress this with javascript?

For those who are unfamiliar with jsonp, it basically injects a script tag, except in my case, I'm hanging the request on my server without returning the request until a later time.

During this time, browsers see my request as a "loading" state.

I am using this: http://code.google.com/p/jquery-jsonp/

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

擦肩而过的背影 2024-10-01 11:52:21

如果您在页面加载完成后开始第一个请求,您应该能够避免加载指示器。

$(function () {
    setTimeout(function () {
        $.jsonp(...)
    }, 1000);
});

If you begin your first request after the page has finished loading, you should be able to avoid the loading indicator.

$(function () {
    setTimeout(function () {
        $.jsonp(...)
    }, 1000);
});
提笔书几行 2024-10-01 11:52:21

据我所知,无论你为什么拥有它,都没有办法使用 Javascript 来抑制加载状态。

然而,跨域 COMET 至少有一个替代方案,它不会首先触发加载状态。 XMLHttpRequest 不会设置加载状态,根据我的测试,允许跨域 XHR 的 CORS(跨源资源共享)规范得到了很好的支持。

基本上,支持如下:(根据浏览器文档和我自己对我正在从事的项目的测试)

完全支持:

  • Gecko 1.9.1+(Firefox 3.5,SeaMonkey 2.0等。测试良好的Firefox 3.6 .8 和 SeaMonkey 2.0.7)
  • WebKit(Safari 4+、Chrome 3+ 等。已测试在 OSX 上的 Safari 4、WinXP 上的 Safari 5、Chrome 5.0.375.127(稳定通道)、Midori 0.2.7,新的 羊群主显节 2.30.2, luakituzbl)

未经测试,但应该完全支持:

  • Fluid(基于 WebKit 的 MacOS Mozilla Prism 和 Chrome 的“创建应用程序快捷方式...”的替代方案)

有限支持:

  • Internet Explorer 8 ( Microsoft 实现了一个 XDomainRequest() 对象,并且以安全为借口,没有实现通过请求传递凭据和 cookie 的标志)
  • Sleipnir (支持取决于嵌入的 MSHTML 版本)

特别不受支持:

  • Opera(截至 1190 年 1 月 11 日,不再支持)
  • Camino(如2.0.5 版本,仍然基于 Gecko 1.9.0 (Firefox 3.0))
  • Arora (从0.10.2开始,继承了WebKit的CORS API,但有一个导致请求失败的错误)
  • 旧的,基于Mozilla的Flock(基于Gecko 1.9.0(Firefox 3.0))

这不是完整的列表,但它是每个带有用户脚本的浏览器我可以找到测试的支持。我已经花时间在CORS 维基百科页面上引用了我的资料来源,如果您想要他们。

我能想到的最简单的解决方案是 测试 CORS 然后回退到 JSONP,以便使用现代浏览器的人获得完美的体验,而使用旧浏览器的人将加载状态视为不可避免的副作用。

以下是关于CORS 工作原理的 MDC 页面。

As far as I know, there is no way to suppress the loading status using Javascript, regardless of why you have it.

However, there is at least one alternative for cross-domain COMET which wouldn't trigger the loading status in the first place. XMLHttpRequest doesn't set the loading status and, according to my tests, the CORS (Cross-Origin Resource Sharing) spec which allows cross-domain XHR is pretty well supported.

Basically, support is as follows: (According to a mix of browser documentation and my own tests for a project I'm working on)

Full support in:

  • Gecko 1.9.1+ (Firefox 3.5, SeaMonkey 2.0, etc. Tested good Firefox 3.6.8 and SeaMonkey 2.0.7)
  • WebKit (Safari 4+, Chrome 3+, etc.. Tested working on Safari 4 on OSX, Safari 5 on WinXP, Chrome 5.0.375.127 (Stable channel), Midori 0.2.7, the new Flock, Epiphany 2.30.2, luakit, and uzbl)

Untested, but should be fully supported:

  • Fluid (WebKit-based MacOS alternative to Mozilla Prism and Chrome's "Create Application Shortcuts...")

Limited support in:

  • Internet Explorer 8 (Microsoft implemented an XDomainRequest() object instead and, using security as an excuse, didn't implement the flag to pass credentials and cookies with the request)
  • Sleipnir (Support is determined by which version of MSHTML it's embedding)

Notably unsupported:

  • Opera (As of 11.01.1190, no support whatsoever)
  • Camino (As of 2.0.5, still based on Gecko 1.9.0 (Firefox 3.0))
  • Arora (As of 0.10.2, inherits WebKit's CORS API but has a bug that causes requests to fail)
  • old, Mozilla-based Flock (Based on Gecko 1.9.0 (Firefox 3.0))

It's not a complete list, but it's every browser with userscript support I could find to test. I've already taken the time to cite my sources on the CORS wikipedia page if you want them.

The simplest solution I can think of would be to test for CORS and then fall back to JSONP so that people using a modern browser get a perfect experience and people using something older see the loading status as an unavoidable side-effect.

Here's the MDC page on how CORS works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文