jsp缺少对象问题

dddzizi 2008-12-22 11:51:17

一个教程上的例子,一直报缺少对象错误,麻烦帮看看哪儿的问题,谢谢!
jsp文件:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ajax基础教程 动态创建结果表</title>

<script type="text/javascript">
var ajax = null;

function initAjax(){
if(window.ActiveXObject){

ajax = new ActiveXObject("Microsoft.XMLHTTP");

}else if(window.XMLHttpRequest){

ajax = new XMLHttpRequest();
}
}

function doit(){
initAjax();
ajax.onreadlystatechange = handstatechange;
ajax.open("GET","simple02.xml",true);
ajax.send(null);
}

function handstatechange(){

if(ajax.readyState==4){
if(ajax.status==200){
clearResults();
paresResults();
}
}
}

function clearResults(){

var header = document.getElementById("header");
if(header.hasChildNodes){
header.removeChild(header.childNodes[0]);
}
var ttbody = document.getElementById("resultsBody");
while(ttbody.childNodes.length>0){
ttbody.removeChild(ttbody.childNodes[0]);
}
}

function paresResults(){

var results = ajax.responseXML;
var property = null;
var address ="";
var price = "";
var comment = "";

var properties = results.getElementsByTagName("property");
for(int i=0;i<properties.length;i++){
property = properties[i];
address = property.getElementsByTagName("address")[0].firstChild.nodeValue;
price = property.getElementsByTagName("price")[0].firstChild.nodeValue;
comment = property.getElementsByTagName("comment")[0].firstChild.nodeValue;
addTableRow(address,price,comment);
}
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 addTableRow(address,price,comment){
var row = document.createElement("tr");
var cell = createCell(adress);
row.appendChild(cell);

cell = createCell(price);
row.appendChild(cell);

cell = createCell(comment);
row.appendChild(cell);

document.getElementById("resultsTable").appendChild(row);
}

function createCell(text){
var cell = document.createElement("td");
var textNode = document.createTextNode(text);
cell.appendChild(textNode);
return cell;
}

function test(){
alert("1111");
}
</script>
</head>
<body>
<form action="#">

<select>
<option>
dgdfddf
</option>
<option>
34
</option>
<option>
bfddf
</option>
</select>

<select>
<option>
fdffd
</option>
<option>
333
</option>
<option>
bbdc
</option>
</select>

<input type="button" value="search" onclick="doit();" />
</form>

<span id="header"></span>
<table id="resultsTable">
<tbody id="resultsBody"></tbody>
</table>
</body>
</html>


simple02.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<property>
<address>address1</address>
<price>44</price>
<comment>dkal,die,dlll</comment>
</property>
<property>
<address>address2</address>
<price>66</price>
<comment>3jj,dkf,lak</comment>
</property>
<property>
<address>address3</address>
<price>88</price>
<comment>jkkd,iiekk,dll</comment>
</property>
</properties>
...全文
362 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cobly123456789 2010-05-27
  • 打赏
  • 举报
回复
EWREW
qqlpp 2008-12-22
  • 打赏
  • 举报
回复
不懂,帮顶
neo_yoho 2008-12-22
  • 打赏
  • 举报
回复
var properties = results.getElementsByTagName("property");
for(int i=0;i <properties.length;i++){
property = properties[i];
这个错了
应该是
var properties = results.getElementsByTagName("property");
for(var i=0;i <properties.length;i++){
property = properties[i];
dddzizi 2008-12-22
  • 打赏
  • 举报
回复
谢谢 neo_yoho
是这个原因。。

52,797

社区成员

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

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