Can you please tell me if you spot a problem.. when I run the page nothing appears.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Simple Ajax</title>
<script>
window.onload = makeRequest;
var xhr = false;
function makeRequest(){
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { }
}
}
}
if (xhr) {
xhr.onreadystatechange = showState;
xhr.open("GET", "states.xml", true);
xhr.send(null);
}
else {
document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create a request";
}
function showState() {
var currMsg = document.getElementById("updateArea").innerHTML;
document.getElementById("updateArea").innerHTML = currMsg + "<p>The current state is " + xhr.readyState + " and the status is " + xhr.status + "</p>";
}
</script>
</head>
<body>
<div id="updateArea"> </div>
</body>
</html>
You can find the XML file at...
http://www.testwebdesign.com/states.xml