Created
April 9, 2018 17:28
-
-
Save NicholasEli/47f66bb01cdf4e7ff78674aad95987c5 to your computer and use it in GitHub Desktop.
Vanilla JS xhttp requst with json
This file contains hidden or 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
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