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 synchronou开发者_如何学Cs 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!
may be you need to look at xmlCurr.responseText ?
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.
精彩评论