I'm attempting to create a basic AJAX example, but I'm encountering issues getting it to function correctly.
Below is the code I have:
<script>
function loadXMLDoc() {
var xmlhttp;
if (window.XMLhttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
//Code for IE6 and IE5
xmlhttp = new ActiveXObject(Microsoft.XMLHTTP);
}
xmlhttp.onreadystatechange = function() {
if ((xmlhttp.readystate == 4) && (xmlhttp.status == 200)) {
document.getElementbyId("mydiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", ajax_info.txt, "true");
xmlhttp.send();
}
</script>
The objective is to fetch data from a .txt file, but when I press the button, it fails to function as intended.
Here is the code within the body:
<div id="mydiv"><h2>Allow Ajax to alter this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Modify content</button>