I have an issue with jQuery, where trying to fetch an XML document it comes back as #document in the console as opposed to an object I can act on. Why is this?
Here is my JavaScript code:
$.get('/ingredients/view_xml/' + ingredientId, function(xml) {
console.log(xml);
}, 'xml');
And here is the XML:
<?xml version="1.0" encoding="UTF-8" ?>
<ingredient>
<entryId>700</entryId>
<title>GUINEA FOWL WHOLE FRESH X 1.5KG</title>
<ingredientUnit>KG</ingredientUnit>
<ingredientCost>5.03</ingredientCost>
</ingredient>
Any help would be greatly appreciated, even if it is a n00b mistake I’ve made and can’t see right now!
This is the intended behaviour, see documentation:
Further, the document is parsed using jQuery.parseXML() which is simply a wrapper around the browser’s “native” XML parsing. The resulting document can be traversed and manipulated using the DOM, or, more conveniently, using jQuery. Example from doc: