AJAX学习中的问题

「已注销」 2011-11-08 04:17:47
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()函数这里报出一个错误“对象不支持此属性或方法”
我找不到是哪个对象不支持哪个属性或方法,对照书本都对了好几次都不知道什么错误
希望各位前辈指点一下!
...全文
118 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2011-11-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zell419 的回复:]
testdoSearch = > doSearch
要学会利用工具 。写这么一大段肯定有些错误的 。
[/Quote]
已经将doSearch修改为testdoSearch了,但是jsunit依然报相同的错误,而且页面没有预期的效果...
郁闷死了
zell419 2011-11-08
  • 打赏
  • 举报
回复
testdoSearch = > doSearch
要学会利用工具 。写这么一大段肯定有些错误的 。

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧