Here\'s what I am doing,
Get request to my web server, response is in json. Using jquery templates to render that callback data in my app. Pretty straightforward, works
You need to use JSON like so:
localStorage.setItem('foo', JSON.stringify(data));
And then parse it:
JSON.parse(localStorage.getItem('foo'))
App.local = (function () {
var self = {};
self.get = function (key) {
var b = localStorage.getItem(key);
return b ? JSON.parse(b) : null;
}
self.set = function (key, value) {
var b = JSON.stringify(value);
localStorage.setItem(key, b);
}
return self;
})();
Now you have a nice interface to local storage,
var local = App.local;
local.set('foo', 'bar');
var bar = local.get('foo');
console.log(bar);