dynamicContent.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//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>Dynamically</title>
<script type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
<script type="text/javascript">
var xmlHttp;
function testcreateXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function testdoSearch(){
testcreateXMLHttpRequest();
xmlHttp.onreadystatechange = testhandleStateChange;
xmlHttp.open("GET","dynamicContent.xml",true);
xmlHttp.send(null);
}
function testhandleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
testclearPreviousResults();
testparseResults();
}
}
}
function testclearPreviousResults(){
var header = document.getElementById("header");
if(header.hasChlidNodes()){
header.removeChild(header.childNodes[0]);
}
var tableBody = document.getElementById("resultsBody");
while(tableBody.childNodes.length > 0){
tableBody.removeChild(tableBody.childNodes[0]);
}
}
function testparseResults(){
var results = xmlHttp.responseXML;
var property = null;
var address = "";
var price = "";
var comments = "";
var properties = results.getElementsByTagName("property");
for(var i = 0; i < properties.length; i++){
property = properties[i];
address = property.getElementsByTagName("address")[0].firstChild.nodeValue;
price = property.getElementsByTagName("price")[0].firstChild.nodeValue;
comments = property.getElementsByTagName("comments")[0].firstChild.nodeValue;
addTableRow(address, price, comments);
}
var header = document.createElement("h2");
var headerText = document.createTextNode("Results:");
header.appendChild(headerText);
document.getElementById("header").appendChild(header);
document.getElementById("resultsTable").setAttribute("border", "1");
}
function testaddTableRow(address, price, comments){
var row = document.createElement("tr");
var cell = testcreateCellWithText(address);
row.appendChild(cell);
cell = testcreateCellWithText(price);
row.appendChild(cell);
cell = testcreateCellWithText(comments);
row.appendChild(cell);
document.getElementById("resultsBody").appendChild(row);
}
function testcreateCellWithText(text){
var cell = document.createElement("td");
var textNode = document.createTextNode(text);
cell.appendChild(textNode);
return cell;
}
</script>
</head>
<body>
<h1>search real</h1>
<form action="#">
Show listings from
<select>
<option value="50000">$50,000</option>
<option value="100000">$100,000</option>
<option value="150000">$150,000</option>
</select>
to
<select>
<option value="100000">$100,000</option>
<option value="150000">$150,000</option>
<option value="200000">$200,000</option>
</select>
<input type="button" value="Search" onclick="doSearch();" />
</form>
<span id="header"></span>
<table id="resultsTable" width="75%" border="0">
<tbody id="resultsBody">
</tbody>
</table>
</body>
</html>
dynamicContent.xml
<?xml version="1.0" encoding="utf-8"?>
<properties>
<property>
<address>no.1 Street</address>
<price>$100,000</price>
<comments>quiet, serene</comments>
</property>
<property>
<address>no.2 Street</address>
<price>$110,000</price>
<comments>no problem</comments>
</property>
<property>
<address>no.3 Street</address>
<price>$115,000</price>
<comments>come on!</comments>
</property>
</properties>
我在学习ajax的过程中,按照书本打出以上代码,但无论如何都不能运行出应有的效果,使用了jsunit测试,发现在testclearPreviousResults()函数这里报出一个错误“对象不支持此属性或方法”
我找不到是哪个对象不支持哪个属性或方法,对照书本都对了好几次都不知道什么错误
希望各位前辈指点一下!