我正在尝试在本地存储上缓存 jason 数据以在没有互联网连接时加载它,但当我重新启动应用程序时,我认为本地存储已清除
这是我的代码
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("offline", function() {
alert("No internet connection");
$.each(JSON.parse(localStorage.getItem('foo')), function(key, val) {
if(!(val.php)){val.php=0;}
$('ul.get-mertchant').append('<li> <a href="azkadenya.html?id=' + val.nid + '&nop='+ val.php +'" class="li-link"><div class="circle-img"><img src="'+ val.logo + '" /></div><div class="merchant-info"><h1>'+ val.node_title +'</h1><p>You Have '+ val.php +' Binggz</p></div><div class="more-icon"></div></a> </li>');
});
}, false);
$.getJSON('mywebsite/views/services_merchant_mobile', function(data) {
localStorage.setItem('foo', JSON.stringify(data));
var items = [];
$.each(JSON.parse(localStorage.getItem('foo')), function(key, val) {
if(!(val.php)){val.php=0;}
$('ul.get-mertchant').append('<li> <a href="azkadenya.html?id=' + val.nid + '&nop='+ val.php +'" class="li-link"><div class="circle-img"><img src="'+ val.logo + '" /></div><div class="merchant-info"><h1>'+ val.node_title +'</h1><p>You Have '+ val.php +' Binggz</p></div><div class="more-icon"></div></a> </li>');
});
})
}
怎么了??