Read local file in Phonegap

I am trying to read a local file in Phonegap to load language strings for an application, and I cannot get it to work :(

The code is pretty simple:

var pathToLocalFile = "/home/user/android/assets/www/js/";
var langCache = new FileReader();
langCache.onload = function(data){
  col = JSON.parse(data);
  refreshAllStrings();
};
langCache.onerror = function(err){
  debug.error(err);
};
langCache.readAsText(pathToLocalFile+currentLang+'.json');

This code does not work on the Ripple emulator, and I replaced it with

var pathToLocalFile = "file:///android_asset/www/js/";

in case of android, with the same result:

Uncaught TypeError: Object #<Console> has no method 'warning' cordova-2.4.0.js:2616
initRead cordova-2.4.0.js:2616
FileReader.readAsText cordova-2.4.0.js:2660    
loadLanguage

In Ripple emulator, I launched Chrome using google-chrome -–allow-file-access-from-files, and in the Android configuration and manifest there are all permissions for and plugins are installed.

Of course, I'm missing something, but any idea what it could be?

Sincerely.

+5
source share
2 answers

www , '/home/..' 'file:///'. "AJAX", .

$.get('js/filename.ext');
+5

, , , cordova-2.4.0.js "". console.warn. , readAsText , .

, console.warn " FileReader.readAs ".

+1

All Articles