What is Ajax's header's role? Why do we need this?
And in this specific case below, what cause the differences between with xhttp.setRequestHeader()
and without?
<!DOCTYPE html>
<html>
<body>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
}
xhttp.open("POST", "demo_post2.asp", true);
// xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("fname=Henry&lname=Ford");
</script>
</body>
</html>