topical media & game development
professional-web-03-XMLHttpRequest.htm / htm
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function processResponse() {
if (xhr.readyState == 4) {
var nodes = xhr.responseXML.documentElement.childNodes;
var membersList = document.getElementById("members");
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType == 1) {
var name = nodes[i].childNodes[0].nodeValue;
var li = document.createElement("li");
li.appendChild(document.createTextNode(name))
membersList.appendChild(li);
}
}
}
}
function loadSimpsons() {
xhr = window.ActiveXObject
? new ActiveXObject("Microsoft.XMLHTTP")
: new XMLHttpRequest();
xhr.onreadystatechange = processResponse;
xhr.open("GET", "http://www.example.com/simpsons.xml", true);
xhr.send("");
}
</script>
</head>
<body>
<p>
<button onclick="loadSimpsons()">Load family</button>
</p>
<ul id="members">
</ul>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.