客户端数据存储

I have the following situation: the user submits a form, I fetch the data from the server via an Ajax request and displays a chart. However, I want to give the user the option to display the data in the chart in table form or export as csv after he had submitted the form.

I was wondering what's the best solution to store the data, considering that I don't want the data to persist if the user opens a new window to submit the form again for example.

The application is in Rails.

Thanks.

You have a few options:

Cookies LocalStorage SessionStorage

More info: https://developer.mozilla.org/en/DOM/Storage

Non-standard:

window.name can store anywhere from 1mb up to 10mb depending on the browser. This is more of a hack, but is fairly stable. You would need to implement your own accessor/setter methods on this, where localStorage and sessionStorage have API's built in.

Personally i would recommend local storage if all your users browsers support it.

Its very simple to use and you can access it using these to methods.

localStorage.getItem("Itemkey");
localStorage.setItem("Itemkey","value");
localStorage.removeItem("ItemKey");

Its always a good way to go and this means you can assign each window a differnt local storage key and even remove the item when the window is closed, or unloaded !

For reference I found this very useful: http://diveintohtml5.info/storage.html

And combine it with storing JSON objects ( http://www.json.org/js.html ) and you have a very fast,simple and easy to use solution. OR even just store a string,array or what ever is required.