HTTP works as a request–response convention in the client–server figuring model. A web program, for instance, might be the customer and an application running on a PC facilitating a site might be the server. The customer presents a HTTP ask for message to the server. The following is an example by using
GET
.
[html]
<!DOCTYPE html>
<html>
<body bgcolor="skyblue">
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Request data</button>
<p id="splesson5"></p>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("GET", "demo_get.asp", true);
xhttp.send();
}
</script>
</body>
</html>
[/html]
The server, which gives assets, for example, HTML records and other substance, or performs different capacities in the interest of the customer, gives back a reaction message to the customer. The reaction contains fruition status data about the demand and may likewise contain asked for substance in its message body.
The
getElementById()
strategy gives back the component that has the ID quality with the predetermined esteem. This strategy is a standout amongst the most widely recognized strategies in the HTML DOM, and is utilized practically every time user need to control, or get information from, a component on the archive.
The readystate essentially implies that the demand has got done with preparing. 200 is the http status for OK.
Output:Now compile the code result will be as follows.