到节点服务器的HTTPRequest在IE 8中有效,但在IE 7中无效 [英] HTTPRequest to Node server works in IE 8 but not IE 7
本文介绍了到节点服务器的HTTPRequest在IE 8中有效,但在IE 7中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试为具有IE 7的用户找到解决方法.基本上,在我的客户端javascript应用程序中,以下代码向运行node.js的服务器发出httprequest,如果客户端具有IE8,则连接成功,但是在IE7中不成功.有想法吗?
Trying to find a work around for users who have IE 7. Basically in my client-side javascript application the below code makes a httprequest to a server running node.js and I get a succesful connection if the client has IE8 but it's unsuccesful in IE7. Thoughts?
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
not sure but you need to tweak CreateXmlHttpReq
function to handle different types of Microsoft's 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;
}
这篇关于到节点服务器的HTTPRequest在IE 8中有效,但在IE 7中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文