尽管我在后台运行挂起的 AJAX 请求,如何使 Web 浏览器完成加载过程?

发布于 2024-12-01 10:58:56 字数 222 浏览 1 评论 0原文

我正在尝试实现一个简单的“comet”ajax长轮询机制(如此处所述)。

问题是,我无法弄清楚如何告诉浏览器就像已完成加载页面一样,尽管它有一个正在后台运行的待处理请求。 (一种

方法是使用网络套接字,但这太过分了。

I am trying to implement a simple "comet" ajax long-polling mechanism (as described here).

The problem is, I cannot figure out how to tell the browser to act as if it has finished loading the page, although it has a pending request running in the background. (The l

One way is using web sockets, but that's way much of an overkill.

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

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

发布评论

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

评论(3

你的笑 2024-12-08 10:58:56

啊,老的“厄运的悸动者”:-)

关于此的另一个问题可能值得一读。它指的是 IFRAME,但很可能仍然相关。

我写了一篇关于 throbber 的帖子我正在研究 Kwwika,但我得出了一个不幸的结论:100% 摆脱它并不容易。

我认为 WebSockets 实际上并没有太大的杀伤力。使用 XMLHttpRequest 等的 Comet 并不是 Web 浏览器从根本上支持的标准。换句话说,他们并没有竭尽全力让创建长期存在的 HTTP 请求变得超级容易。 WebSocket 是一种标准化方法,正在缓慢但坚定地受到所有浏览器的支持。我希望他们能进入 IE10。现在,您可以查看类似 web-socket-js 的内容,这将确保 WebSocket 支持在 99% 的浏览器中。与任何类型的轮询解决方案相比,WebSocket 还提供更低的延迟和更少的资源密集度。

Ah, the old "throbber of doom" :-)

There's another question about this which is probably worth a read. It refers to IFRAMEs but it's most probably still relevant.

I wrote up a post on the throbber while I was working on Kwwika but I came to the unfortunate conclusion that's it's not very easy to 100% get rid of it.

I'd suggest that WebSockets aren't actually overkill. Comet using XMLHttpRequest etc. isn't a standard fundamentally supported by web browsers. In other words they don't go out of their way to make creating long-lived HTTP requests super-easy. WebSockets are a standardised approach that are slowly but surly becoming supported in all browsers. I'm hoping that they make it into IE10. For now you can look at something like web-socket-js which will ensure WebSocket support in 99% of browsers. WebSockets also offer lower latency and are less resource-intensive that any kind of polling solution.

万劫不复 2024-12-08 10:58:56

您需要异步调用ajax http://api.jquery.com/jQuery.ajax/

You need async call to ajax http://api.jquery.com/jQuery.ajax/

沉溺在你眼里的海 2024-12-08 10:58:56

好的,我已经设法解决了这个问题。出现“throbber of doom”的问题是因为我在 document.ready 函数下执行了 ajax 请求,如下所示:

$(function() {$.ajax ... });

这解决了它:

$(function() { setTimeout(connect, 1000); });

OK, I've sorta managed to solve this. The problem of the "throbber of doom" was caused because I executed the ajax request under the document.ready function like this:

$(function() {$.ajax ... });

This solved it:

$(function() { setTimeout(connect, 1000); });

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