tags:

views:

123

answers:

2

can anyone please point me in the right direction for a json database on the client side for the duration of the pages life.

example:

i have a page with a canvas that i can add elements to and move them around, but i wish to create a Json object so that if an item is added to the canvas, the details are also added or updated in the json. i use asp.net MVC C#.

ideally a good example of add item and edit item and if possible using jquery but any kind of javascript would at least give me a clue.

thanks

+1  A: 

Is Question 2010892 - Storing Objects in HTML5 localStorage of any relevance to you?

David Heggie
this is for html5 i need it for html 4, 5 is not really viable for a few years yet i dont think.... hell we STILL have to support IE6 :-) but thanks anyway simular kind of lines but dont know this storageobject ???
minus4
Google Gears maybe? http://gears.google.com/You can have a local SQLite database that you could save your JS data in - http://code.google.com/apis/gears/api_database.html
David Heggie
Or I've just found the jQuery JSON Cookie plugin which stores JSON data in cookies - http://lab.distilldesign.com/json-cookie/ which may help you out too.
David Heggie
+1  A: 

a few clarification points:

  • when you say "for the duration of the pages life", you mean without any page reloading? if so, then you don't need storage, just put all relevant data in a variable (such as an array). the JavaScript environment won't be lost until you reload the page.

  • if it will be client side only, and not stored somewhere else, you don't need JSON. in fact there's no such thing as a 'JSON object'. JSON is a text representation of an object; i.e. a string. What you manipulate in JavaScript are JavaScript objects, which can be represented as JSON on a string, or constructed from a string using JSON format.

that said, if you want a multi-browser library to store JavaScript object on the client side,persist.js looks interesting. It's a JS library that shows a common API over several incompatible solutions, including proprietary APIs, cookies and Flash.

Javier
yeah this is more in line with what i was thinking, i build a string like json and at the end i then serialize and post, before sending the user to the next page, but need some way to say go to ID 22 that could be the third element and change the X and Y coords to the new location of the element. in the past i have been posting after draggable stops but want to limit these post down if i can...... thanks
minus4