-->

Cache manifest causes $.getJSON to stop

2019-09-08 22:37发布

问题:

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

回答1:

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
*