JElster
asked on
AngularJS - how to read a local (resource?) JSON file
Hi..
I need to read a local JSON file that contains mapping info.
What the correct/best way to read it?
Do I use HTTP GET? or Resource?
I need to read a local JSON file that contains mapping info.
What the correct/best way to read it?
Do I use HTTP GET? or Resource?
you could also of course just reference the file in plain old script tag..
ASKER
It's a local mobile app
not sure what you mean by 'local'.
Does it run in the browser, or is there some kind of wrapper like phonegap?
Does it run in the browser, or is there some kind of wrapper like phonegap?
ASKER
Just looking for code and suggestions... uses cordova too..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So how do I read a local JSON file without having to select it?
Something like this>
var reader = new FileReader();
var file = 'data/myJSON.json'
reader.readAsDataURL(file) ;
thx
Something like this>
var reader = new FileReader();
var file = 'data/myJSON.json'
reader.readAsDataURL(file)
thx
You can't. You have to select it.
There is no standard way of reading a file in such a covert manner. The only way I can think of is to write an ActiveX control, which would also considerably limit the target OS and browsers.
You can however use webstorage and WebSQL (all new goodies that come with HTML5) and save content locally. This should however should only be treated as a caching mechanism and you cannot rely on the content to be always there.
You can however use webstorage and WebSQL (all new goodies that come with HTML5) and save content locally. This should however should only be treated as a caching mechanism and you cannot rely on the content to be always there.
imagine the security nightmare if websites could have access to your computer's files!
you could have a button that loads the file, but the user would have to select the file.
if the question is about developing your app on your local computer, then in order to make ajax requests you would need to 'host' your app. in other words, you need a localhost, or virtual host on your computer to serve your app