We have an App works with cordova [phonegap] we wish to perform offline saving of a results into cache memory
results comes from the server [PHP] than using ajax & javascript results shown in the webview
I try to use localStorage for keeping last used values [2] when user is in offline mode [no wifi/3G]. USD/EURO or USD/ILS i.e.
using jQuery normally works
$('.loading').fadeOut();
var $response = $(result);
var result = $response.filter('#result').html();
var result_1 = $response.filter('#result_1').html();
var result_10 = $response.filter('#result_10').html();
var result_100 = $response.filter('#result_100').html();
var result_1000 = $response.filter('#result_1000').html();
$('.convertfrom_txt').each(function() { $(this).text(cfrom_str); })
$('.convertto_txt').each(function() { $(this).text(cto_str); })
$('#cresult').text(result + ' ' + cto_str);
$('#one_unit').text(result_1);
$('#ten_unit').text(result_10);
$('#hundred_unit').text(result_100);
$('#thousand_unit').text(result_1000);
Offline assuming value changes everyday. [currencies]
var currency = [10]; //10 currencies max to save offline
var currency = result_1 ; //save result of 1 coin to array
var offline;
//Check connection
function onDeviceReady() {
var offlineData = window.localStorage.getItem("result_1");
if (window.navigator.onLine) offline = false;
}
if (offline == false)
{
document.getElementById('result_1').value = "currency[0]";
document.getElementById('result_10').value = "currency[0]*10";
document.getElementById('result_100').value = "currency[0]*100";
document.getElementById('result_1000').value = "currency[0]*1000";
document.getElementById('time').value = "time";
}
result_1 represents the value of one conversion. we wish to store values of 1 USD and 1 Euro in an array, offline
I 'm not sure which better way to choose
localStorage taken form official Docs
var storage = localStorage;
var value = storage.getItem(key); // Pass a key name to get its value.
storage.setItem(key, value) // Pass a key name and its value to add or update that key.
storage.removeItem(key) // Pass a key name to remove that key from storage.
- Will such local storage works under common Android devices?
Thanks