Skip to content

Instantly share code, notes, and snippets.

@HDDen
Created January 6, 2024 19:47
Show Gist options
  • Save HDDen/9a4dfa33e428ab0f3a59367b3c51ba6e to your computer and use it in GitHub Desktop.
Save HDDen/9a4dfa33e428ab0f3a59367b3c51ba6e to your computer and use it in GitHub Desktop.
js json send
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState != 4) return;
if (this.status == 200) {
var data = JSON.parse(this.responseText);
// we get the returned data
}
// end of state change: it can be after some time (async)
};
xhr.open("POST", yourUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
value: value
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment