<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”
“” rel=”nofollow” target=”_blank” title=”http://www.w3.org/TR/xhtmll/DTD/xhtll…”>http://www.w3.org/TR/xhtmll/DTD/xhtll…
<html xmlns=”” rel=”nofollow” target=”_blank” title=’http://www.w3.org/1999/xhtml”>’>http://www.w3.org/1999/xhtml”>
<head>
<script type=”text/javascript”>
<!–定义一个变量–>
var xmlHttp;
<!–创建函数–>
function createXMLHttprequest()
{
<!–判断window 对象表示一个浏览器窗口或一个框架 Activexobject对象是启用并返回 automation 对象的引用–>
if(window.ActiveXObject)
{
<!–实例化xmlHtto –>
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
<!–否则 如果 window 调用 XMLHttpRequest–>
else if (window.XMLHttpRequest)
{
<!–实例化xnlHttp–>
xmlHttp = new XMLHttpRequest();
}
}
<!–创建函数–>
function startRequest()
{
<!–createXMLHttpRequest 创建一个XMLHttpRequest–>
createXMLHttpRequest();
<!–xmlHttp 调用 onreadystatechange 属性储存了回调函数的指针 handleStateChange 取得头部数字–>
xmlHttp.onreadystatechange = headleStateChange;
<!–xmlHttp 发送请求给innerHTML.xml文件 –>
xmlHttp.open(“GET” , “innerHTML.xml” , true);
<!–开始发送–>
xmlHttp.send(null);
}
<!–创建函数–>
function handleStateChange()
{
<!–判断xmlHttp的返回值类型 等于 4–>
if(xmlHttp.readyStat == 4)
{
<!–判断xmlHttp返回的数值 等于 200–>
if(xmlHttp.state == 200)
{
<!–显示 resulteID innerHTML等于 返回的字符串–>
document.getElementById(“results”).innerHTML = xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form action=”#”>
<input type=”button” value=”Search” for Tody “s Activities” onclick = “startRequest();” />
</form>
<div id=”results”></div>
</body>
</html>
报的错误是createXMLHttpRequest(); is not defined(repeated 3 times)
innerHTML.xml
<table border=”1″>
<tbodt>
<tr>
<th>Activity Name</th>
<th>Location</th>
<th>Time</th>
</tr>
<tr>
<td>Watrskiing</td>
<td>Dock #1</td>
<td>9:00 AM</td>
</tr>
<tr>
<td>Volleyvall</td>
<td>East Court</td>
<td>2:00 PM</td>
</tr>
<tr>
<td>Hiking</td>
<td>Trail 3</td>
<td>2:00 PM</td>
</tr>
</tbody>
</table>
注意大小写。。。
js是大小写敏感的