I’m trying to get the contents of an xml file using jQuery’s ajax function.
$(document).ready(function(){
$.ajax({
url: 'facts.xml',
dataType: 'xml',
success: parseXML
});
function parseXML(xml){
alert(xml.toSource());
//...
}
}
facts.xml is simple:
<?xml version="1.0" encoding="utf-8"?>
<axiom>
<sentence>
<part>something</part>
</sentence>
</axiom>
When I run it in firefox, alert gives me “({})”. I’ve been trying to identify where I was doing wrong, but I couldn’t figure it out. Can anyone give me some help?
Thanks a lot!
toSourceis supposed to give you the equivalent of the JavaScript source for the object in question, but it can’t and doesn’t work for just any object. Try asking the DOM object for something else, such as.documentElement.tagNameinstead.