HTTPRequest to Node 服务器适用于 IE 8,但不适用于 IE 7
HTTPRequest to Node server works in IE 8 but not IE 7
试图为拥有IE 7的用户找到解决方法。 基本上在我的客户端 javascript 应用程序中,下面的代码向运行节点的服务器发出 httprequest.js如果客户端有 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) {}
}
不确定,
但您需要调整CreateXmlHttpReq
函数来处理不同类型的Microsoft的ActiveXObjects
function CreateXmlHttpReq(handler) {
var xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
var types = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Microsoft.XMLHTTP"];
for (var i = 0; i < types.length; i++) {
try {
xmlhttp = new ActiveXObject(types[i]);
break;
} catch(e) {}
}
}
if (xmlhttp) {
xmlhttp.onreadystatechange = handler;
}
return xmlhttp;
}
相关文章:
- AngularJS$http.post没有'不适用于Chrome,仅适用于IE
- 如何调试遗留的javascript代码(适用于IE,但在Google Chrome中不正常)
- js不适用于Chrome,但适用于IE
- (PHP&JavaScript)a href添加按钮赢得'我不适用于Mozilla,但适用于IE和谷歌
- javascript代码适用于IE和Chrome,但不适用于Firefox
- html5 canvas 中的 OffsetX 适用于 IE、Safari、Chrome,但不适用于 Firefox
- .load() 适用于 IE 和 dreamweaver 预览版,但不能使用 opera 和 chrome
- IE 9 Javascript Window Variable 为 null.适用于IE 8
- Javascript / CSS不适用于IE 10,但适用于IE 8
- html 选择列表更改无法在谷歌浏览器上调用方法(适用于 IE)
- 此代码阻止我的表单提交(仅在 chrome 中,适用于 IE 和 Firefox)
- Jquery适用于IE以外的所有浏览器
- Fotorama - 适用于IE,Firefox,但不适用于Chrome(上传到服务器)
- JavaScript适用于IE,但不适用于Firefox和Chrome
- javascript 函数 - 传递给函数的变量适用于IE,但不适用于Firefox
- HTTPRequest to Node 服务器适用于 IE 8,但不适用于 IE 7
- Javascript window.print 适用于 IE 和 FF,但不适用于 Chrome(在旧版本中曾经如此)
- 两个几乎相等的jQuery函数;一个适用于IE,一个不适用于IE
- 寻找适用于IE的开发人员插件
- Firefox 中的 HTML 位置问题(适用于 IE 和 Chrome)