This is how I solved it. First set the file paths that are different for Android and iOS
var file_path; function setFilePath() { if(detectAndroid()) { file_path = "file:///android_asset/www/res/db/";
Then I upload the JSON files that are pre-packaged in the application to the local storage of the browser. Like this:
localStorage["my_json_data"] = loadJSON(file_path + "my_json_data.json"); function loadJSON(url) { return jQuery.ajax({ url : url, async : false, dataType : 'json' }).responseText; }
If I want to update my data. I get new JSON data from the server and paste it into local storage. If the server is in a different domain, which is used in most cases, you need to make a JSONP call (check jQuery documents for JSONP ). I did it like this:
$.getJSON(my_host + 'json.php?function=' + my_json_function + '&callback=?', function (json_data) {
j7nn7k Nov 26 '11 at 13:37 2011-11-26 13:37
source share