(This is for local use only, using WAMP) I have some Javascript's that create a array containing some string and objects. I would like to save this array to a file, so that i can later load it into another JavaScript.
I have seached Google all night, but can seem to find any way of doing this :(
(This is for local use only, using WAMP) I have some Javascript's that create a array containing some string and objects. I would like to save this array to a file, so that i can later load it into another JavaScript.
I have seached Google all night, but can seem to find any way of doing this :(
Share Improve this question asked Nov 21, 2013 at 1:49 Dennis Sødal ChristensenDennis Sødal Christensen 2251 gold badge4 silver badges15 bronze badges 3- 2 Use the browser's localstorage if you don't need an actual file but only to store/load data on different pages (different scripts) of your site. – Bergi Commented Nov 21, 2013 at 1:56
- @Bergi is absolutely correct on this one, localStorage is what you want and need. – Rob M. Commented Nov 21, 2013 at 2:02
- localstorage is good but what if he needs the data in other browser? – StaleMartyr Commented Nov 21, 2013 at 2:41
3 Answers
Reset to default 2use JSON.stringify(myarray)
first, then you can use AJAX to send the data to the server. You can use file_put_contents
(php) to save the file to the server's disk...you can retrieve the array and use it later using JSON.parse(array_from_file);
You can send json to php server and from there you can write it to a json file.
If you are doing this locally, you can constrain yourself to Chrome and use the HTML5 FileWriter API. Here's a guide to get you started. Also, you can check on the status of the browser patibility matrix here.
Also, you might want to consider using the HTML5 LocalStorage or SessionStorage API's as well.
There's also the HTML5 FileSystem API polyfill that uses IndexedDB.