How To Save My Javascript Array To A File?
Solution 1:
If you are using phonegap than for sure you can work with file system.
Solution is to encode your array into JSON
using serializeArray()
method in JQuery.
Once you encode your array you will get JSON
string which you have to store in a file using PhoneGap's Filewriter()
function. For more detail on that visit this link.
I hope it helped you :-).
Solution 2:
Phonegap (at http://phonegap.com/tools/) is suggesting Lawnchair: http://westcoastlogic.com/lawnchair/
so you'd read that file into data.js instead of storing the data literally there
Solution 3:
You could also save your array (or better yet its members) using localStorage, a key/value storage that stores your data locally, even when the user quits your app. Check out the guide in the Safari Developer Library.
Solution 4:
use Lawnchair to save the array as a JSON object. The JSON object will be there in the memory till you clear the data for the application. If you want to save it permanently to a file on the local filesystem then i guess you can write a phonegap plugin to sent the data across to the native code of plugin which will create/open a file and save it.
Solution 5:
JavaScript cannot tamper with the file system directly. You can do one of two things:
- Save the changes onto a cookie and read it the next time
Send the changes (via AJAX) to a PHP file which would generate a downloadable file on the server, and serve it to the client.
There are probably more solutions, but these are the most reasonable two I can think of.
Post a Comment for "How To Save My Javascript Array To A File?"