【发布时间】:2017-04-10 10:30:11
【问题描述】:
我被告知 MsXML2 遵循重定向。但是,当访问已移动的 URL 时,我从脚本中收到“HTTP 0”错误。
我需要让它工作的原因是因为这是一个被 30 万用户使用的 Windows(侧边栏)小工具。我正在移动网站,并希望所有对旧版本的调用仍然通过。
这是简化的代码:
function MyHttpCall() {
var httpReq = new ActiveXObject("Msxml2.XMLHTTP.6.0");
httpReq.onreadystatechange = function() {
if (httpReq.readyState < 4) return;
if (httpReq.status != 200) alert("HTTP " + httpReq.status);
alert ("Houston we have contact");
}
httpReq.open("GET", myURL, true);
httpReq.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
httpReq.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
httpReq.setRequestHeader("Pragma", "no-cache");
httpReq.setRequestHeader("If-Modified-Since", "Tue, 01 Jan 2008 00:00:00 GMT");
httpReq.send();
}
我认为这与 httpReq.status != 200 有关,但我认为 readystatechange 会在状态更改后不断触发事件。为 HTTP 301 触发一个,为 HTTP 200 触发另一个。
【问题讨论】:
标签: javascript ajax xmlhttprequest msxml