I need to read an attribute or node from my xml file. It is on the same server as the html page. Is it wrong to use an ajax call or should I use more native js to extract the data? I need to access the data in Jquery to dynamically output it in html. I don't wont to loop through the whole xml file really, all I want to do is get one of the child's of Picture. I know in php I can write:
$questions = (string)$xml->question[2];
as an example and that would get me the third question in my xml file. I want to know the equivalent to that line to get the second element in jquery.
In my code I have
<script language="JavaScript" type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "Pictures.xml",
datatype: "xml",
error: function(jqXHR, textStatus, errorThrown) {
console.log('Error: ' + errorThrown);
},
success: function(xml) {
console.log('AJAX Request is succeded.');
title =
$(xml).find('Picture')(1).find('title').text();//this line wont wrong
document.getElementById("picture").innerHTML = title;
}
});
});
</script>
So can anyone help me find just the title for the second Picture title in the xml file.