Created
February 9, 2018 10:01
-
-
Save taimursaeed/fabe4c9e746b8d6579a80b128c2543a9 to your computer and use it in GitHub Desktop.
Storing and Retrieving JSON from Local Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function storeItem(itemName, data) { | |
localStorage.setItem(itemName, btoa(JSON.stringify(data))); | |
} | |
function retrieveItem(itemName) { | |
var x = localStorage.getItem(itemName); | |
if (!x) { console.log("Element not found in local storage"); return false; } | |
localStorage.removeItem('x'); | |
x = atob(x); | |
return $.parseJSON(x); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment