Firebug 在下面的第 10 行给了我一个语法错误:
switch(xmlhttp.readyState) {
这直接来自 Christian Gross 的“Ajax 模式和最佳实践”一书的第 2 章。提前致谢。我似乎看不到语法错误。任何帮助表示赞赏。
<html>
<head>
<title>Sample Page</title>
<script language="JavaScript" src="/lib/factory.js"></script>
<script language="JavaScript" type="text/javascript">
var xmlhttp = FactoryXMLHttpRequest();
function AsyncUpdateEvent() {
switch(xmlhttp.readyState) {
case 0:
document.getElementById('status').innerHTML = "uninitialized";
break;
case 1:
document.getElementById('status').innerHTML = "loading";
break;
case 2:
document.getElementById('status').innerHTML = "loaded";
break;
case 3:
document.getElementById('status').innerHTML = "interactive";
break;
case 4:
document.getElementById('status').innerHTML = "complete";
document.getElementById('result').innerHTML = xmlhttp.responseText;
break;
}
}
function GetIt(url) {
if(xmlhttp) {
xmlhttp.open('GET', url, true);
xmlhttp.onreadystatechange = AsyncUpdateEvent;
xmlhttp.send(null);
}
}
</script>
</head>
<body>
<button onclick="GetIt('/chap02/serverhang.aspx')">Get a document</button>
<p><table border="1">
<tr>
<td>Document</td>
<td>
<span id="status">No Result</span>
</td>
<td>
<span id="result">No Result</span>
</td></tr>
</table></p>
</body>
</html>