开发者

How do I cause the web browser to complete the loading process, although I am running pending AJAX requests in the background?

开发者 https://www.devze.com 2023-03-30 05:01 出处:网络
I am trying to implement a sim开发者_开发百科ple \"comet\" ajax long-polling mechanism (as described here).

I am trying to implement a sim开发者_开发百科ple "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.


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.


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


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); });

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号