所以这是代码,我从教程中得到了它,但是当我实际运行它时,它给了我一个未被捕获的错误,上面写着
无法读取属性' documentElement' null handleServerResponse
这是Javascript文件:
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject(){
var xmlHttp;
if (window.ActiveXObject) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
xmlHttp = false;
}
}
else {
try {
xmlHttp = new XMLHttpRequest();
} catch(e){
xmlHttp = false;
}
}
if (!xmlHttp)
alert("Cannot create object!");
else
return xmlHttp;
}
function express() {
if (xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
word = encodeURIComponent(document.getElementById("input").value);
xmlHttp.open("GET", "chuffbucket.php?word=" + word, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}
else {
setTimeout('express()', 1000);
}
}
function handleServerResponse(){
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
xmlResponse = xmlHttp.responseXML;
xmlDocumentElement = xmlResponse.documentElement;
message = xmlDocumentElement.firstChild.data
document.getElementById("comment").innerHTML = '<span style="color: blue">' + message + '</span>';
setTimeout('express()', 1000);
}
}
else {
alert("No chalk in the house!");
}
}