0

I am developing a mobile app using HTML5, Javascript, jQuery Mobile, and offline storage.

I have a wep app that serves an array of JSON objects to the mobile app (on the same domain). It gets the JSON objects, stores them in a websql database then creates a unordered list with them which can be clicked...

The idea is that when the device is in offline mode I will pull the data from the offline database and bypass getting the JSON from the web app, then when the device is next online it can get a fresh copy of the data.

I've got to the part where I am creating my cache.manifest file. Basically it looks like this:

CACHE MANIFEST

CACHE:
index.html
app.html

NETWORK:
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css
http://code.jquery.com/jquery-1.4.3.min.js
js/data.js
js/script.js

However as soon as I add

<html  manifest="cache.manifest">

And reload the page my $.getJSON stops (can be found in data.js). Other JS code in that file seems to execute but that function.

Here is the function that gets executed on load:

function getAppointments(){
// Update appointments ONLY when online
if(navigator.onLine = true){
    console.log('Application Online.')

    // create appointments table
    createAppTable();
    $.getJSON("http://site.com/OptiQuoteApp/index.php/appointments/download/", function(data) {
        $.each(data,function()
        {
            // Save appointments in database
            updateAppointments(this.quote_id, this.start_date, this.reference, this.first_name+' '+this.last_name, this.comment);
        });
         getAppointmentsList();
    });
}else{
    console.log('Application Offline.')

}
getAppointmentsList();

}

Note. I know it says site.com (for security...)

The script gets as far as createAppTable(); then no more.

Any idea anyone?

Billy

Much appreciated

iamjonesy
  • 24,732
  • 40
  • 139
  • 206

1 Answers1

3

Try adding * under "NETWORK:" in your manifest file. That way anything not specifically cached will get pulled from your site.

NETWORK:
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.js
http://code.jquery.com/mobile/1.0a1/jquery.mobile-1.0a1.min.css
http://code.jquery.com/jquery-1.4.3.min.js
js/data.js
js/script.js
*
Eric Farr
  • 2,683
  • 21
  • 30
  • Thanks Eric that seemed to do it! Does this mean that those files won't have been cached though? I'll need js/data.js and js/script.js when offline? Can I have them in CACHE: and NETWORK: ? – iamjonesy Jul 19 '11 at 08:20
  • You should move all of your .js files to the CACHE section. – Eric Farr Jul 20 '11 at 14:47
  • I would put data FALLBACK: URLs and NETWORK: sections. For example, if you always return a JSON boolean item "success" and code you could return a simple JSON such as {"success" : false, "code": "offline"} – King Friday Mar 05 '13 at 21:39