I'm not sure what is wrong all my files are in the same folder. First I will post HTML, then AJAX, and finally the .txt file.
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Title of webpage</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="javascript.js"></script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
And my javascript/AJAX:
function loadXMLDoc(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "test.txt", true);
xmlhttp.send();
}
And my .txt file:
<h3>This text was changed</h3>
<p>And also I added a random paragraph</p>
Thankyou in advance for the help.