I have a AJAX requests which returns a string of XML which I\'d like to inject into the DOM. My function looks like
$.ajax({
type: \'POST\',
url:
Try using:
datatype: 'xml',
instead of 'json', because you're retrieving an XML response. Setting the datatype will result in it being properly parsed as XML.
From this answer:
In XML (and XML-based languages such as XHTML), tagName preserves case. In HTML, tagName returns the element name in the canonical uppercase form. The value of tagName is the same as that of nodeName.
A bit of searching shows that a lot of people experience this problem, especially with selectors and XML (jQuery's find() is case sensitive and selectors used in find() are lowercased).
Here's a function someone else is using to convert a string into XML that may work for you:
$.text2xml = function(sXML) {
// NOTE: I'd like to use jQuery for this, but jQuery makes all
// tags uppercase
//return $(xml)[0];
var out;
try{
var dXML = ($.browser.msie)?new ActiveXObject("Microsoft.XMLDOM"):new DOMParser();
dXML.async = false;
}catch(e){ throw new Error("XML Parser could not be instantiated"); };
try{
if($.browser.msie) out = (dXML.loadXML(sXML))?dXML:false;
else out = dXML.parseFromString(sXML, "text/xml");
}
catch(e){ throw new Error("Error parsing XML string"); };
return out;
}