2011-07-18 70 views
0

我正在開發一個使用HTML5,Javascript,jQuery Mobile和離線存儲的移動應用程序。

我有一個wep應用程序,爲移動應用程序提供一組JSON對象(在同一個域上)。它獲取JSON對象,將它們存儲在一個websql數據庫中,然後創建一個可以單擊的無序列表...

這個想法是當設備處於離線模式時,我將從離線數據庫並繞過從Web應用程序獲取JSON,然後當設備下一次在線時,它可以獲得新的數據副本。

我已經到了創建我的cache.manifest文件的部分。一旦

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 

但是我添加

<html manifest="cache.manifest"> 

和重裝,我的$ .getJSON停止頁面(可在data.js找到):基本上,它看起來是這樣的。該文件中的其他JS代碼似乎執行但該函數。

這裏是獲取負載執行的功能:

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(); 

} 

注意。我知道它說site.com(爲安全...)

該腳本得到儘可能createAppTable();那麼沒有更多。

任何想法的人?

比利

非常感謝

+0

你有沒有在這裏錯過'==':'navigator.onLine = true'? –

+0

另外,也許一些相關的信息在https://github.com/jquery/jquery-mobile/issues/1579 –

+0

評論您好凱文,我意識到,我發佈後,但改變它並沒有解決問題。雖然 – iamjonesy

回答

3

嘗試增加*在 「Network:」 在您的清單文件。這樣,沒有專門緩存的任何內容都會從您的網站中撤出。

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 
* 
+0

感謝埃裏克,似乎這樣做!這是否意味着這些文件不會被緩存?離線時我需要js/data.js和js/script.js嗎?我可以讓他們在CACHE:和NETWORK:? – iamjonesy

+0

您應該將所有.js文件移至CACHE部分。 –

+0

我會把數據FALLBACK:網址和網絡:部分。例如,如果您總是返回一個JSON布爾項「success」並且代碼可以返回一個簡單的JSON,如{「success」:false,「code」:「offline」} –