我一直在研究一个 Windows 小工具(意思是“浏览器”是 Internet Explorer),它可以查询指定的子网地址以获取信息。现在,它有时会以相对较快的速度(大约每 5 秒)执行此操作,并且效果很好。但是,有时它会卡在就绪状态 1 并永远停留在那里。每当小工具尝试重做用于获取 xmlhttprequest 并从中获取信息的函数时,它将保持在状态 1。当打开小工具的多个实例然后关闭除一个之外的所有实例时,这很容易复制。那时,仍然打开的那个几乎总是会陷入这种状态。我觉得这可能与他们都访问同一个网站有关,或者它可能只是与 xmlhttprequests 在传输过程中停止并阻止另一个工作有关。下面是相关代码。
//Reference to this for the inner function
var me = this;
var request = new XMLHttpRequest();
request.onreadystatechange = onReadyStateChange;
var url = this.url;
//Make the URL random to prevent being cached
url += ("&a=" + ((new Date()).getTime()));
Trace(DEBUG_COMM, "Sase.updateStatus url: " + url);
request.open("GET", url, true);
request.send(); // fire off the request, calls httpRequestReadyStateChange as things continue
Trace(DEBUG_COMM, "Request sent" + request.readyState);
function onReadyStateChange() {Trace(DEBUG_COMM, "Sase.httpRequestReadyStateChange: state=" + request.readyState);
if (4 == request.readyState) {
Trace(DEBUG_COMM, "Sase.httpRequestReadyStateChange: status=" + request.status);
if (request.status == 200) {
Trace(DEBUG_COMM, "retrieved html: " + request.responseText);
var results = request.responseText;
var resultsString = request.responseText.toString();
Trace(DEBUG_COMM, "results String: " + resultsString);
me.ParseStatusData(resultsString);
}
else {
//me.commError(request.status);
}
request = null;
}
}