I’m creating a form that collects standard information about customers. When the user hits save, I would like to create a .txt file that would be used to later retrieve all of the data collected from customers. I’m using DataTables which is a jQuery plugin to display the data. The .txt file would be formatted to be saved as such:
{
"aaData": [
["client 1 name", "address", "city", "state", "zip"],
["client 2 name", "address", "city", "state", "zip"],
["client 3 name", "address", "city", "state", "zip"],
...["client x name", "address", "city", "state", "zip"]
]
}
Where “aaData”: is used by DataTables. This is going to part of an iPhone app, so the data source has to be very small and not reliant on a constant connection to a server, so, essentially, a client-side data source. The .txt file has to also be updated when edited and saved, and then replaced every time it is downloaded.
Do you want to save a .txt file locally (i.e., on the client computer)? That’s not possible: for (obvious) security reasons, a browser’s JavaScript environment is unable to access the local file system. You can save this JSON-formatted data in a cookie (max. 4 KB per cookie) or, with HTML 5, using localStorage.