admin管理员组文章数量:1425142
(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.
本文标签: JavaScriptSaveLoad array to a fileStack Overflow
版权声明:本文标题:JavaScript : SaveLoad array to a file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745395602a2656799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论