我使用以下代码创建XMLHttpRequest对象。但状态为0,readyState始终为1。请指导我做出的错误。
代码流程从updateAllZipsDTVEligible函数开始。
var request;
function createRequest() {
if ( typeof XMLHttpRequest != "undefined" ) {
return new XMLHttpRequest();
} else if ( window.ActiveXObject ) {
var versions = [ "MSXML2.XMLHttp.5.0",
"MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp", "Microsoft.XMLHttp" ];
for ( var i = 0; i < versions.length; i++ ) {
try {
xmlHttp = new ActiveXObject(versions[i]);
return xmlHttp;
} catch ( e ) {}
}
}
throw new Error("XMLHttp object could not be created.");
}
function runQuery(method, readyFunc) {
request = createRequest();
request.open("GET", "../dispatcher/updateDTV/" + method, true);
request.onreadystatechange = function () {
if ( request.readyState == 4 ) {
if ( request.status == 200 ) {
readyFunc();
} else {
alert("Status = " + request.status);
}
}
};
request.send(null);
}
function updateAllZipsDTVEligible() {
//var countySelected = document.getElementById("countyId").value;
var countySelected = "23185";
runQuery("updateDTVEligible?countyId=" + countySelected, updateMsg);
}