JavaScript : SaveLoad array to a file? - Stack Overflow

(This is for local use only, using WAMP)I have some Javascript's that create a array containing s

(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
Add a ment  | 

3 Answers 3

Reset to default 2

use 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745395603a4625863.html

相关推荐

  • JavaScript : SaveLoad array to a file? - Stack Overflow

    (This is for local use only, using WAMP)I have some Javascript's that create a array containing s

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信