Created
January 6, 2024 19:47
-
-
Save HDDen/9a4dfa33e428ab0f3a59367b3c51ba6e to your computer and use it in GitHub Desktop.
js json send
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(); | |
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