I'm loading an xml file with jQuery ajax loader, and need to convert it to a string so that I can save it out again using PHP post variables. What is the best way to do this?
<script type='text/javascript'>
jQuery.ajax({
type: "GET",
url: "data.xml",
dataType: "xml",
success: parseXML
});
function parseXML(xml) {
var xml_string = jQuery(xml).text(); // (This doesn't work- returns tagless, unformatted text)
alert(xml_string);
}
</script>
Had the same problem - xmlString was returning an empty string. Adding [0] to jQuery selector helped to address XML-type object:
Your Javascript:
jQuery:
Spent much time for this problem. With IE 9 above functions should work in another way. Because in IE9
xmlData[0].xml
doesn't work (IE still likes jokes). And we must useXMLSerializer
with IE v9 and higher (?!)And example of using it with jQuery 1.8.2 (1.6.4 works too).
You can use following function:
Pass jquery xml object to this function
In my case
Is not working. This is issue with IE10.
So I am able to fix this issue as follows:
And working fine with any browser.
This worked for me (credit: http://www.ibm.com/developerworks/xml/tutorials/x-processxmljquerytut/section3.html):
Here's an example that retrieves information about a column from a SharePoint list: