Skip to content

Instantly share code, notes, and snippets.

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 NicholasEli/47f66bb01cdf4e7ff78674aad95987c5 to your computer and use it in GitHub Desktop.
Save NicholasEli/47f66bb01cdf4e7ff78674aad95987c5 to your computer and use it in GitHub Desktop.
Vanilla JS xhttp requst with json
const jsonObject = {
//key values
}
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//on complete
}
}
xhttp.open("POST", "/path_to_call", true)
xhttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8')
xhttp.send(JSON.stringify(jsonObject))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment