It’s supposed to display 172-ajax-include.php when the user clicks the submit button. But it doesn’t work. I think I did it right. Can’t figure out what I did wrong.
<html>
<head>
<script type="text/javascript">
function load()
{ /* start function load */
if (window.XMLHttpRequest)
{ /* 1 if start */
xmlhttp = new XMLHttpRequest();
} /* 1 if end */
else
{ /* 1 else start */
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
} /* 1 else end */
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 /* the 200 makes sure that it's not empty*/)
{ /* 2 if start */
document.getElementById('adiv'),innerHTML = xmlhttp.responseText;
} /* 2 if end */
xmlhttp.open('GET', '172-ajax-include.php', true);
xmlhttp.send();
}
} /* end function load */
</script>
</head>
<body>
<input type="submit" onclick="load();">
<div id="adiv"></div>
</body>
</html>
open() and send() must be placed outside the onreadystatechange handler.
EDIT:
Change html button