0

I have a webapp where my employees take quizes(Multiple choice question) .I have to save user response in json format and submit the response to server when user hits the submit button but When a person is going through a quiz and suddenly its system crashes or shutdown due to some reason I want to be able to save the progress of user locally.What I want is to store that json data locally till the time user submits the quiz and once user hits the submit button the local data should be destroyed.So that in case if system crashes I can collect the user progress from participant system manually.So is thr any way to store data locally using javascript?

user1170793
  • 210
  • 1
  • 12

3 Answers3

6

You can use local storage from HTML5

localStorage.setItem(id, value);

To retrieve the storage value use:

localStorage.getItem(id);
noob
  • 8,053
  • 4
  • 34
  • 64
Victor
  • 7,620
  • 14
  • 74
  • 121
  • for that my browser has to be HTML5 compliant and secondary it would not be in a file format which i could collect manually in a thumbdrive – user1170793 Jun 12 '12 at 12:31
  • In case of system crash will this data persists in localstorage when I start the system next time? – user1170793 Jun 12 '12 at 12:35
  • It depends from your browser. According with the documentation this should work as you wish. You can test. – Victor Jun 12 '12 at 12:37
  • @Victor he has asked after a HTML5 solution by adding the HTML5 tag to his question so he should know that he needs HTML5 support. Btw as you can see it's already supported in [IE8](http://caniuse.com/#search=localstorage) – noob Jun 12 '12 at 12:46
  • 1
    @user1170793 yes it will but you'll need to save the data directly after your employee has choosen an answer all the time. – noob Jun 12 '12 at 12:47
0

It depends on precisely which browsers you have to support.

For newer browsers, you can use HTML5 local storage. There's plenty of information about using this available already, as well as this SO question asking for good guides about using local storage.

For older browsers, you'll probably want to use cookies. Again, plenty of information on using cookies available already.

Community
  • 1
  • 1
Anthony Grist
  • 37,428
  • 8
  • 62
  • 73
0

Some wrappers exists for client-side persistent storage.

Take for example Amplify.Store: http://amplifyjs.com/api/store/

I have no experience with it, but is supposed to utilize the HTML 5 storage features and automatically fallback to technologies supported by older browsers.

I hope this helps.

Munk
  • 155
  • 1
  • 8