I am trying to get myself started with Ajax so I was just trying to load some content from a file on click of a button but the content of other file is not loaded
<!DOCTYPE html>
<html>
<head>
<script>
function loadData()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("output").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","a1.html",true);
xmlhttp.send();
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadData()">Request data</button>
<div id="output"></div>
</body>
</html>
a1.html file is present under same folder where this html file is.