I am new to AJAX and I am following the tutorial from w3cSchool.com .
I basely set up a info.txt file (dummy data) on my desktop and run a html page on my desktop (i.g. under same folder) to get the text, but I end up with nothing. When I check out my xmlhttp.status, it returns with 0 value which doesn't make sense to me (the value should be either 200 or 404)
Please help me up, thanks a lot!
here is my html code:
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
else
{
document.getElementById("myDiv").innerHTML=xmlhttp.status;
}
}
xmlhttp.open("GET","info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
here is my info.txt code:
<p>123</p>
<p>AJAX is a technique for creating fast and dynamic web pages.</p>