试图为拥有 IE 7 的用户找到解决方法。基本上在我的客户端 javascript 应用程序中,下面的代码向运行 node.js 的服务器发出 httprequest,如果客户端有 IE8 但它在 IE7 中不成功,我会获得成功的连接. 想法?
var myxmlhttp;
doRequest();
function doRequest() {
var url = "http://someserver:8000/" + username;
myxmlhttp = CreateXmlHttpReq(resultHandler);
if (myxmlhttp) {
XmlHttpGET(myxmlhttp, url);
} else {
alert("An error occured while attempting to process your request.");
// provide an alternative here that does not use XMLHttpRequest
}
}
function resultHandler() {
// request is 'ready'
if (myxmlhttp.readyState == 4) {
// success
if (myxmlhttp.status == 200) {
alert("Success!");
// myxmlhttp.responseText is the content that was received
} else {
alert("There was a problem retrieving the data:\n" + req.status.text);
}
}
}
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// users with activeX off
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
if (xmlhttp) xmlhttp.onreadystatechange = handler;
return xmlhttp;
}
// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
try {
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
} catch (e) {}
}