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: "myrequest",
data: postdata,
datatype: 'json',
success: function (arguments) {
newxmlstring = arguments.newxml;
oldnode = $("someselector specified in the arguments passed");
oldnode.replaceWith(newxmlstring);
}
});
This works but it appears that the replaceWith function maps all nodeName into capitalized versions of the response sent by the server. I’m assuming this is some quirk with trying to use jQuery to handle XML?
So for example if the response string is <data>asdf</data> when I access $(newnode)[0].nodeName I get 'DATA'.
Does anybody know how to handle the new XML while preserving the nodeName in lower case?
EDIT: My response is JSON since it contains the new xml string and a bit of other data about where to attach the new xml node. So I’d prefer to keep datatype: 'json' if at all possible.
From this answer:
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: