使用 Google Chrome 加载指示器

发布于 2024-09-11 10:14:58 字数 689 浏览 4 评论 0原文

我在使用 Google Chrome 或更确切地说 Android (2.1) 网络浏览器时遇到问题。

我的网络应用程序在每次页面切换时都会调用restservices。这需要一些时间,我需要为用户提供反馈,例如一个小“正在工作...”弹出窗口。 Restservices 通过同步 ajax 请求调用。这是一个例子:

$.ajax({
    url: some URI,
    async: false,
    beforeSend: function() {
        showIndicatorDialog();
    },
    complete: function() {
        hideIndicatorDialog();
    },
    success: function(response) {
        do something after success;
    },
    error: function(response) {
        do something after error;
    },
    type: 'GET'
});

这在 FF 和 Opera 上效果很好!但是,当我使用 Android 设备在 Chrome 或 Chrome 上访问我的网络应用程序时,加载指示器不会出现!谷歌浏览器似乎不支持同步请求。

有人知道我如何让它工作或者知道另一种解决方案来在 chrome 中获取加载指示器吗?

I have problem with Google Chrome or rather Androids (2.1) webbrowser.

My webapp calls restservices with each page shift. This takes some time and I need a feedback for the user like a little "working..." popup . The restservices are called with a sync ajax request. Here is an example:

$.ajax({
    url: some URI,
    async: false,
    beforeSend: function() {
        showIndicatorDialog();
    },
    complete: function() {
        hideIndicatorDialog();
    },
    success: function(response) {
        do something after success;
    },
    error: function(response) {
        do something after error;
    },
    type: 'GET'
});

That works great on FF and Opera! But when I visit my webapp on Chrome oder with my Android device the loading indicator doesnt appears! It seems that the Google browser don't work with synchrchronous requests.

Does someone know how I can get this to work or knows another solution to get a loading indicator in chrome??

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

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

发布评论

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

评论(2

才能让你更想念 2024-09-18 10:14:58

解决方案是不使用同步请求。一般来说,永远不要使用同步请求,因为它们往往会阻止页面上其他任何内容(甚至整个浏览器 UI)的执行,这是不好的。

The solution is not to use synchronous requests. In general, synchronous requests should never be used because they tend to block the execution of anything else on the page (or even the entire browser UI), which isn't good.

笑,眼淚并存 2024-09-18 10:14:58

您是说加载指示器不会显示在 Google Chrome(桌面版)上,还是仅显示在 Android 设备的移动版 Google Chrome Lite 浏览器上?如果您使用的是最新版本的 jQuery,那么它应该适用于所有桌面浏览器。移动浏览器由于界面设计截然不同而没有得到很好的支持,而且由于不是完整的浏览器,许多浏览器没有功能齐全的 JS 支持。

也就是说,我还没有听说 Chrome Lite 中的 jQuery 有任何问题——Android 平台最令人印象深刻的事情之一就是在移动平台上包含了功能齐全的浏览器。但我认为 jQuery 的移动版本要么可用,要么正在开发中。所以如果其他方法都失败了,你可以尝试一下。

有关移动浏览器上 JavaScript/jQuery 支持的概要,请参阅此 Google 网上论坛帖子:
http://groups.google.com/group/jquery-dev/msg/ 262fa7d9f3cbe96e

编辑:
虽然 Chrome 的 UI 在执行同步请求时似乎会锁定,但我只需在显示加载指示器和执行 XHR 之间稍加延迟就可以解决这个问题:

function callAjax() {
    showIndicatorDialog();
    setTimeout("testAjax()",100);
}
function testAjax() {
    foo = $.ajax({
        url: "index4.htm",
        global: false,
        type: "POST",
        data: {
            id: 3
        },
        dataType: "html",
        async:false,
        success: function(msg){
            $('#response').text(msg);
        },
        complete: hideIndicatorDialog
    }).responseText;
}

我使用了 POST 请求来阻止浏览器缓存响应,但这对于 get 请求应该同样有效。我没有 Android 手机来测试它,但它在 Google Chrome 中运行良好。

Are you saying that the loading indicator doesn't show up on Google Chrome (desktop) as well or just the mobile Google Chrome Lite browser for Android devices? If you are using the latest version of jQuery, then it should work on all desktop browsers. Mobile browsers are not well-supported due to their drastically different interface design and, not being full browsers, many do not have fully functional JS support.

That said, I have not heard of any problems with jQuery in Chrome Lite—one of the most impressive things about the Android platform is the inclusion of a fully functional browser on a mobile platform. But I think there is a mobile version of jQuery either available or in the works. So if all else fails, you could try that.

For a rundown of JavaScript/jQuery support on mobile browsers, see this Google Groups post:
http://groups.google.com/group/jquery-dev/msg/262fa7d9f3cbe96e

Edit:
While Chrome's UI does seem to lock up while you're performing a synchronous request, I was able to get past this by simply putting a slight delay between showing the loading indicator and performing the XHR:

function callAjax() {
    showIndicatorDialog();
    setTimeout("testAjax()",100);
}
function testAjax() {
    foo = $.ajax({
        url: "index4.htm",
        global: false,
        type: "POST",
        data: {
            id: 3
        },
        dataType: "html",
        async:false,
        success: function(msg){
            $('#response').text(msg);
        },
        complete: hideIndicatorDialog
    }).responseText;
}

I used a POST request to prevent the browser from caching the response, but this should work equally well with get requests. I don't have an Android phone to test it on, but it works fine in Google Chrome.

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