views:

404

answers:

1

Hello!

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,

+2  A: 

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('...')

Rafael