Google Gears 和 jQuery 创建托管商店时出现问题

发布于 2024-07-18 16:28:27 字数 1315 浏览 5 评论 0原文

我正在尝试创建一个 ManagedStore 来缓存我正在开发的 Web 应用程序中的所有 js、img、swf 和 css。

这是代码:

$(document).ready(function() {
    var manifestName = 'cache_manifest.json';
    var storeName = 'cache';
    var localServer;
    var localStore;
    if (window.google && google.gears) {
        localRequest = google.gears.factory.create('beta.httprequest');
        localServer = google.gears.factory.create('beta.localserver');
        localStore = localServer.openManagedStore(storeName);
        isServerAvailable();
        $("#separator").text(' | ');
        if (!localStore) {
                localStore = localServer.createManagedStore(storeName);
                localStore.manifestUrl = manifestName;
                localStore.onerror = $('#offline').text('Error con el cache');
                localStore.oncomplete = $('#offline').text('Cache activado');
                localStore.onprogress = $('#offline').text(Math.ceil(((event.filesComplete / event.filesTotal) * 100)) + "%");
                localStore.checkForUpdate();
        }
        else {
            $('#offline').text('Cache activado');
        }
    }
});

但是,localStore.onerror 总是会被触发。

我有疑问:

  • 你知道出了什么问题吗?
  • 我怎样才能看到实际的错误是什么(alert(localStore.onerror) 不起作用)

问候,

I'm trying to create a managedStore to cache all the js, img, swf and css from a web app I'm developing.

Here is the code:

$(document).ready(function() {
    var manifestName = 'cache_manifest.json';
    var storeName = 'cache';
    var localServer;
    var localStore;
    if (window.google && google.gears) {
        localRequest = google.gears.factory.create('beta.httprequest');
        localServer = google.gears.factory.create('beta.localserver');
        localStore = localServer.openManagedStore(storeName);
        isServerAvailable();
        $("#separator").text(' | ');
        if (!localStore) {
                localStore = localServer.createManagedStore(storeName);
                localStore.manifestUrl = manifestName;
                localStore.onerror = $('#offline').text('Error con el cache');
                localStore.oncomplete = $('#offline').text('Cache activado');
                localStore.onprogress = $('#offline').text(Math.ceil(((event.filesComplete / event.filesTotal) * 100)) + "%");
                localStore.checkForUpdate();
        }
        else {
            $('#offline').text('Cache activado');
        }
    }
});

However, localStore.onerror always get's triggered.

I have to questions:

  • Any ideas what's going wrong?
  • How can I see what's the actual error ( alert(localStore.onerror) won't work)

Regards,

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

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

发布评论

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

评论(1

听不够的曲调 2024-07-25 16:28:28

尝试

if (!localStore) {
   localStore = localServer.createManagedStore(storeName);
   localStore.manifestUrl = manifestName;
   localStore.onerror = function(){$('#offline').text('Error con el cache');}
   localStore.oncomplete = function(){$('#offline').text('Cache activado');}
   localStore.onprogress = function(){$('#offline').text(Math.ceil(((event.filesComplete / event.filesTotal) * 100)) + "%");}
   localStore.checkForUpdate();
}

您必须分配对函数的引用,这些函数应该在定义的事件上调用。 你所做的就是调用这些函数,最后 onerror、oncomplete 和 onprogress 属性保存 $('#offline').text('...') 返回的 jQuery 实例

try

if (!localStore) {
   localStore = localServer.createManagedStore(storeName);
   localStore.manifestUrl = manifestName;
   localStore.onerror = function(){$('#offline').text('Error con el cache');}
   localStore.oncomplete = function(){$('#offline').text('Cache activado');}
   localStore.onprogress = function(){$('#offline').text(Math.ceil(((event.filesComplete / event.filesTotal) * 100)) + "%");}
   localStore.checkForUpdate();
}

you have to assign references to functions, that should be called on defined events. What you did was calling these functions, and on the end the onerror, oncomplete and onprogress properties held jQuery instances returned by $('#offline').text('...')

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