var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject() {
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
function process() {
if (xmlHttp) {
xmlHttp.open("GET", "bacon.txt", true);
xmlHttp.onreadystatechange = handleServerResponse();
xmlHttp.send(null);
}
}
function handleServerResponse() {
theD = document.getElementById('theD');
if (xmlHttp.readyState == 1) {
theD.innerHTML += "Status 1:server connection established";
}
if (xmlHttp.readyState == 2) {
theD.innerHTML += "Status 2:done";
}
if (xmlHttp.readyState == 3) {
theD.innerHTML += "Status 3:done again";
}
if (xmlHttp.readyState == 4) {
if (xmlHttp.status = 200) {
text = xmlHttp.responseText;
theD.innerHTML += "Status 4:request done";
theD.innerHTML += text
}
}
}
我只获得"server connection established"
作为输出。