Cache manifest causes $.getJSON to stop

和自甴很熟 提交于 2019-12-24 22:42:58

问题


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
*


来源:https://stackoverflow.com/questions/6736275/cache-manifest-causes-getjson-to-stop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!