I have this function where i want to parse the xml with jquery.
function xmlParser(xml) {
var xmlTitle = xml.data;
alert($(xmlTitle).find('title'));
}
I want to alert the title of the the xml like this but it doesn’t work. This is what i did, which can be helpful you to see the xml object.
alert(xml);
alert(xml.data);
xml alerts: [object Object.]
xml.data alerts: <data><title>Hello</title><topic>World</topic></data>
That’s an element with the tag
title, which means it’s an object, and alerts can’t show objects, you should use console.log for that. To show the elements text, you could do:FIDDLE
If your getting the XML whith a jQuery method that uses
$.ajax, it should be parsed already, otherwise a good practice is to parse the XML with $.parseXML to make sure jQuery can treat it the usual way.