javascript - How to store temporary data at the client-side and then send it to the server -


i need store data temporarily @ client-side allow users add, edit or delete items without having query server each of these actions; when user finishes adding items , clicks on add button, list sent server saved permanently.

this image describes want achieve. know have use arrays in javascript, don't know how create 1 store objects (in case detail contains :id, price , description).

i hope can me out. in advance. ps: i'm using jsp and... sorry english

sure, since it's table makes sense have array of objects. note object surrounded curly braces , array surrounded brackets:

var myarray = [];  // initialize empty array var myobject = {}; // initialize empty object 

this should accomplish need:

// initialize variables var newentry, table = [];  // create new object newentry = {   id: '',   price: '',   description: '' };  // add object end of array table.push(newentry); 

which same this:

// initialize array var table = [];  // create object , add object end of array table.push({   id: '22',   price: '$222',   description: 'foo' }); 

you can access properties this: table[0].id; // '22'

on modern browsers, if want data persist across sessions (like cookies) use sessionstorage or localstorage objects.

when want send data server, you'll send json version of table across wire:

var data = json.stringify(table); 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -