Hi i\'m a beginner in JavaScript i would like to ask if its possible to session the data i\'m getting from a server. The data i want to session is the \'data.xhr.response\' i se
In your case you can either to choose sessionStorage or localStorage. Both can save the data response for you in the browser. The difference is only the expiry that localStorage wont expire while sessionStorage stores data for one session (data is lost when the browser tab is closed).
So the steps are:
Check your browser to see if it supports webStorage:
if (typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
} else {
// Sorry! No Web Storage support..
}
Implement localStorage:
localStorage.setItem("lastname", "Smith"); // save data
var user = localStorage.getItem("lastname"); // get data
localStorage.removeItem("lastname"); // remove data
Implement sessionStorage:
sessionStorage.setItem('lastname', 'Smith'); // save data
var user = sessionStorage.getItem('lastname'); // get data
sessionStorage.removeItem('dataStored'); // remove data
Hope it helps!