[RESOLVED] Ajax - XML "link" tag not returning anything from jQuery.find()
I'm trying to read and XML file, and one of my tags is <link></link>. When I use jQuery.find('link').text(), I get an empty string. All the other tags are returning correct text. Also, when I simply alert(inputXML), everything is there and correct:
Also, I felt it work mentioning that when I had my XML in a string and converted it to XML using DOMparser.parseFromString(xmlDoc, "text/xml"), everything was working perfectly. The moment I started using the ajax to get an actual XML file, it broke. So I wonder if it may have something to do with the version of XML returned?
Hey, I figured it out. I was setting my jQuery.ajax() option "dataType" to "text/xml", when it should have been "xml" alone. I'm not sure why this affected it, but it did. If anyone's got any insight, I'd love to hear it. I suspect it might have been because jQuery was reading it as an HTML link tag, which is supposed to have no inner content. Calling this one resoved. Thanks.
jQuery.fromXMLString = function(strXML){
if (window.DOMParser) {
return jQuery(new DOMParser().parseFromString(strXML, "text/xml"));
} else if (window.ActiveXObject) {
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = "false";
doc.loadXML(strXML);
return jQuery(doc);
} else {
return jQuery(strXML);
}
};
Using that method call and it appears IE doesn't support it (unless it has been added recently). Are you using IE? Is your Ajax instance returning XML or Text? That could also be a reason. Are you passing {dataType:'text'}?
Bookmarks