While working on my Phonegap project I wanted to load initial data into SQLite. One option is to download it from the internet, but it’s always annoying to notify the user to turn on internet and to wait for all the files to download (especially if you have to download 50 images).
The other option is to load local data. Problem is that identifying the right path to local file can be tricky. But the solution is actually easy.
1 2 3 4 5 |
var path = window.location.href.replace('index.html', ''); $.getJSON(path + "fixtures/initial.json", function(data) { // do something with data }); |
All we need is to get current location, remove index.html to get root folder, append it to path of JSON file and voila.