我有以下代码:
var xmlCurr = new ActiveXObject("Microsoft.XMLDOM");
xmlCurr.async = false;
xmlCurr.load(xmlURL);
return xmlCurr;
来自 xmlCurr 我需要以下信息
xmlCurr.xml
xmlCurr.documentElement
xmlCurr.selectSingleNode("result").text;
此代码在 IE6+ 上运行良好,但在 Chrome 或 Firefox 上不起作用。
我尝试过改编代码
http://www.w3schools.com/Xml/xml_parser.asp
获取某些内容如下:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlCurr=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlCurr=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlCurr.open("GET",xmlURL,false);
xmlCurr.send();
xmlCurr.xml=xmlCurr.responseXML;
return xmlCurr;
但是没有用...
有人有什么想法吗?
更新:
我的代码似乎根本不运行 AJAX。
响应文本=“\r\n”
statusText =“确定”
我不知道如何确定 MIME 类型。但responseXML.xml =“”
更新:
感谢abieganski的建议 http://xkr .us/code/javascript/XHConn/
我必须做一些调整,但它现在几乎可以工作了...
-
出于某种原因 - 我认为我的网站的设计方式 - 我必须将函数更改为同步,而不是使用回调函数异步
我不明白为什么,但我得到了responseText,但没有返回responseXML。因此 selectSingleNode 不起作用。因此我不得不写一段脏代码而不是 selectSingleNode
function selectSingleNode2(aXML,aNode) {
aNode=aNode.substr(2,aNode.length-2);
var b1=aXML.indexOf("<"+aNode+">")+aNode.length+2;
var b2=aXML.indexOf("");
var b3=aXML.substr(b1,b2-b1);
返回b3;
}
有什么想法为什么吗?
谢谢你!
I have the following code:
var xmlCurr = new ActiveXObject("Microsoft.XMLDOM");
xmlCurr.async = false;
xmlCurr.load(xmlURL);
return xmlCurr;
From xmlCurr I need the following information
xmlCurr.xml
xmlCurr.documentElement
xmlCurr.selectSingleNode("result").text;
This code works well on IE6+, but does not work on Chrome or Firefox.
I have tried adapting code from
http://www.w3schools.com/Xml/xml_parser.asp
To get something like the following:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlCurr=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlCurr=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlCurr.open("GET",xmlURL,false);
xmlCurr.send();
xmlCurr.xml=xmlCurr.responseXML;
return xmlCurr;
But to no avail...
Does anyone have any ideas?
Update:
My code does not seem to run the AJAX at all.
The responseText = "\r\n"
The statusText="OK"
I do not know how to determine the MIME type. but the responseXML.xml=""
Update:
Thank you to abieganski for the suggestion from http://xkr.us/code/javascript/XHConn/
I had to do a little tweaking, but it is now almost working...
-
For some reason - I think the way my website is designed -I had to change the function to be synchronous as opposed to asynchronous with a callback function
-
I don't understand why but I got responseText back but not responseXML. Therefore selectSingleNode wouldn't work. Therefore I had to write a dirty piece of code instead of selectSingleNode
function selectSingleNode2(aXML,aNode) {
aNode=aNode.substr(2,aNode.length-2);
var b1=aXML.indexOf("<"+aNode+">")+aNode.length+2;
var b2=aXML.indexOf("</"+aNode+">");
var b3=aXML.substr(b1,b2-b1);
return b3;
}
Any ideas why?
Thank you!
发布评论
评论(2)
可能您需要查看 xmlCurr.responseText ?
may be you need to look at xmlCurr.responseText ?
我会使用一些东西来抽象 IE 和其他浏览器之间关于 XMLHTTP 对象的差异。
简单的事情是:
http://xkr.us/code/javascript/XHConn/
或者你可以使用 jQuery 的 ajax方法。
I'd use something that abstracts the differences between IE and other browsers regarding the XMLHTTP object away.
Something simple would be:
http://xkr.us/code/javascript/XHConn/
Or you could use jQuery's ajax method.