this should be a simple question, but the answer has eluded me for some time now. I seem to have an error in this code, either a scripting typo, or an error in my logic. Could you kindly clarify my problem?
Here’s the code:
function GetQuestion() {
$.ajax({
type: "GET",
url: "questions.xml",
dataType: "xml",
success: function(xml) {
x = 0;
x = $(xml).find('Question').length;
var questionID = $.random(x);
$(xml).find('Question').each(function(){
if(this.ID == questionID) {
var text = $(this).find('BODY').text();
$('#questionBody')[0].innerHTML = text;
}
}); //close each
} //close success
});//close ajax
}; //close function GetQuestion
It’s meant to read in an XML file, search it for a specific item with a random ID, and plug the contents of BODY into a <p> I have in my HTML file. However, it isn’t working as expected. Where have I made an error?
Thanks, Elliot Bonneville
This is just a general observation and not really an answer, but it may help you in the future:
so to clarify :\