tags:

views:

88

answers:

1

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.

+1  A: 

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.

Marcel Korpel
The jQuery plugin accesses the data source and displays it in a table format. I'm looking into HTML5 now, which seems like it will work. But what about saving then deleting the .txt data source on closing the app? When the app is opened, the data is called again.
Adam
@Adam: If you want to save the data, you'll have to use a cookie or send it to the server. If you want to delete the data on closing, just add an `onunload` handler (but this will not work in Opera). You can also delete this data `onload`, which will be fired by every browser (assuming JavaScript is on).
Marcel Korpel
Okay, looks like localstorage is the way to go. Thanks, Marcel. Now onto more fun stuff involving html5. Should I create a new post for that, or can we go on from here?
Adam
@Adam: You're welcome. If you have another question not related to this, you should file a new one. Don't forget to use the `html5` tag if appropiate.
Marcel Korpel