在 ajax 调用上显示 *浏览器* 加载指示器(例如发生回发时)

发布于 2025-01-07 00:39:28 字数 482 浏览 0 评论 0原文

例如:转到您的 Facebook 墙,滚动页面末尾,Facebook 将异步加载更多墙帖子。或者只需单击墙上帖子中的图像。图像对话框(带有注释和较大图像)也正在异步加载。 (您可以使用 firebug 查看 GET 请求)。

但是通过查看 Firefox 选项卡,您会看到加载指示器,就像发生回发时一样。

我知道这可以通过使用 IFrame 并更改其 src 来实现。就像 iGoogle 所做的那样。但我不确定 Facebook 是否使用 IFrame 来加载额外的墙贴。还有其他方法可以实现这一目标吗?

更新:我所说的“加载指示器”并不是指 ajax 指示器。
正如我提到的,浏览器指示器(选项卡左侧的指示器向我们显示页面是否正在加载)更改为加载,就像回发一样。

example: Go to your Facebook wall, scroll the end of the page, Facebook will load more wall posts asynchronously. Or just click on an images in your wall post. The image dialog (with comments and larger image) is loading asynchronously as well. (You can see the GET requests with firebug).

But by looking and the firefox tab, you see the loading indicator, just like when a postback occurs.

I know this can be achieved by using an IFrame and changing its src. Just like what iGoogle does. But I'm not sure if Facebook uses an IFrame to load additional wall posts. Is there another way to achieve this?

Update: by saying "loading indicator" I did not mean an ajax indicator.
As I mentioned the browser indicator (the one at the laft side of a tab showing us if the page is loading) changes to loading like it is a postback.

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

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

发布评论

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

评论(3

不是据我所知。
我的猜测是他们可能将 IFrame src 设置为 ajax 方法,并且在加载时将内容移动到 div (或另一个元素)。

Not AFAIK.
My guess is they probably set the IFrame src to an ajax method and when loaded, they move the content to a div (or another element).

萌︼了一个春 2025-01-14 00:39:28

可以通过 iframe 来完成。简而言之,您附加了一个隐藏的 iframe:

var $loadingIndicator = $('<iframe src="/loading/" class="visuallyhidden">');
$loadingIndicator.appendTo('body');

它必须加载一个停止加载的页面。可能在网站自己的域上,因为浏览器实际上在状态栏中显示正在等待domainname.com

在文件 domainname.com/loading/index.php 中,您输入:

<?php sleep(100);

完成后删除 iframe:

$loadingIndicator.remove();

考虑到这实际上是一个额外的请求,这并不理想。有几个原因:

  • 您的服务器将有很长的请求,可能会影响性能
  • 浏览器将使用少数可用的并发连接之一,因此可能会减慢加载的速度
  • 它会使动画卡顿在我的情况下( Chrome 27/OSX,请求动画帧)。

通过慢速加载技术
通过 https://stackoverflow.com/a/3145840/288906

It can be done with an iframe. In short, you append a hidden iframe:

var $loadingIndicator = $('<iframe src="/loading/" class="visuallyhidden">');
$loadingIndicator.appendTo('body');

It has to load a page that stalls, never loads. Possibly on the website's own domain since the browser actually shows waiting for domainname.com in the status bar.

In the file domainname.com/loading/index.php you put:

<?php sleep(100);

And remove the iframe when done:

$loadingIndicator.remove();

It's not ideal considering this is actually an additional request. A few reasons:

  • your server would have long requests that might have a performance impact
  • the browser would use one of the few concurrent connections available, hence possibly slowing down whatever is loading
  • it makes animations stutter in my case (Chrome 27/OSX, requestAnimationFrame).

via Slow-loading technique
via https://stackoverflow.com/a/3145840/288906

无畏 2025-01-14 00:39:28

我制作了一个基于 jQuery 的库来处理这个问题,这在某些情况下(同源)应该是一个可行的解决方案,并在某些桌面浏览器(至少是现代 Chrome 和 Firefox)中成功触发繁忙指示器,奇怪的是,还有 IE8,但可能不是 IE9 ,并且绝对不是 Safari 或大多数移动浏览器)。

Noisy JSON

基本上,我使用 iframe 方法来触发“busy” ” 指示器,但不会人为地点击单独的“停滞”页面:相反,它只是使用自定义 $.ajaxTransport 来传递隐藏的 iframe,然后解析 json 响应。结果是浏览器显示与您发出的请求直接相关的加载指示器:没有额外的 http 请求。您基本上可以只安装插件,然后通过更改 dataType 参数来决定哪些 ajax 请求应该有噪音,哪些不应该有噪音。

附带说明一下,在 iframe 中加载内容不会在 Safari 和 IE9 中向用户触发任何 UI 反馈,这真是奇怪

I made a jQuery-based library to handle this which should be a viable solution in some situations (same-origin) and successfully trigger busy indicators in some desktop browsers (modern Chrome and Firefox at least, and oddly, also IE8 but probably not IE9, and definitely not Safari or most mobile browsers).

Noisy JSON

Basically, I'm using the iframe approach to triggering "busy" indicators, but without artificially hitting a separate "stalled" page: instead, it just uses a custom $.ajaxTransport for passing through a hidden iframe and then parsing the json response back out. The result is that the browser shows loading indicators that are directly related to the request you're making: no extra http requests. You can basically install just the plugin then decide which ajax requests should be noisy and which shouldn't just by changing the dataType parameter.

As a side note, the fact that loading content in iframes DOESN'T trigger any UI feedback to the user in Safari and IE9 is just bizarre.

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