send post data xmlhttprequest code example
Example 1: how to add json data to xmlhttprequest
var xmlhttp = new XMLHttpRequest();
var theUrl = "/json-handler";
xmlhttp.open("POST", theUrl);
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify({ "email": "[email protected]", "response": { "name": "Tester" } }));
Example 2: xmlhttp js post request
var xhr = new XMLHttpRequest();
xhr.open("POST", '/url', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
}
}
xhr.send("name=Hello&id=world");