How to save / save and access client side data in javaScript?

How to save / save and access client side data in javaScript: JQuery?

I am using jsTree JQuery component: JavaScript.

In bind () from jstree after selecting node i want to save "data"

+3


source to share


2 answers


You might want to look into localStorage .

You can store data on the client machine like this:

var data = { name: 'Bob', age: 12 };
Window.localStorage.setItem('person', data);

      

Then on another page on the same domain, you can get this data:

var data = Window.localStorage.getItem('person');

      



Please note that in some browser security settings, disable localStorage so that it does not work in all situations.

Read more here: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API

Another alternative is the use of cookies .

document.cookie = "name=Bob";
document.cookie = "age=12";
console.log(document.cookie); // displays: name=Bob;age=12

      

+2


source


As @Tom mentioned, Localstorage works great.

Alternative way to store data on the client: (IndexedDB)

This storage system uses a key / value mechanism to store data on the client side.



"IndexedDB is a large-scale NoSQL storage system that allows you to store almost anything in the user's browser. In addition to the usual search, retrieval, and placement operations, IndexedDB also supports transactions." Google

IndexedDB definition on MDN:

IndexedDB is a low-level API for client-side storage of a significant amount of structured data, including files / blobs. This API uses indexes to provide high-performance searches on this data. While DOM storage is useful for storing smaller amounts of data, it is less useful for storing large amounts of structured data. IndexedDB provides a solution.

+2


source







All Articles