What is XMLHttpRequest?

What is XMLHttpRequest?

Team Leader Asked on February 12, 2017 in AJAX.
Add Comment
1 Answer(s)

XMLHttpRequest is an API in the form of an object data whose methods transfer data between a client or web browser and a server.
It provides an easy way to get data from a URL without refreshing the web page. Send data to a web server in the background.XMLHttpRequest is mostly used in AJAX programming.

<!DOCTYPE html>

<html>

<head>
<script>

function loadXMLData(){

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {
document.getElementById("data").innerHTML = xmlhttp.responseText;

}

};

xhttp.open("GET", "sample.php", true);

xhttp.send();

}

</script>

</head>
<body>

<div id="data">

<button type="button" onclick="loadXMLData()">Click here to get data</button>
</div>
</body>

</html>

Team Leader Answered on February 13, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.