Last active
January 25, 2016 09:59
-
-
Save 0xKD/19b47356ad4751728a48 to your computer and use it in GitHub Desktop.
Make HTTP POST using XMLHttpRequest
This file contains 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
var xhr = new XMLHttpRequest(); | |
url = '/url/to/post'; | |
params = JSON.stringify({'key': 'value'}); | |
xhr.open("POST", url, true); | |
xhr.setRequestHeader("Content-Type", "application/json"); | |
xhr.setRequestHeader("Content-Length", params.length); | |
xhr.setRequestHeader("Connection", "close"); | |
xhr.onreadystatechange = function() { | |
if (this.status == 200) { | |
console.log(this.responseText); | |
} | |
} | |
xhr.send(params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment