Answer the question
In order to leave comments, you need to log in
Why doesn't jQuery code work when interacting with xml database?
Hello colleagues! Need help understanding how jQuery code works with an xml database.
Here is the code
$(document).ready(function(){
$("#dvContent").append("<ul></ul>");
$.ajax({
type: "GET",
url: "BookList.xml",
dataType: "xml",
success: function(xml){
$(xml).find('Book').each(function(){
var sTitle = $(this).find('Title').text();
var sPublisher = $(this).find('Publisher').text();
$("<li></li>").html(sTitle + ", " + sPublisher).appendTo("#dvContent ul");
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});
<?xml version="1.0" encoding="UTF-8"?>
-<BookList>-<Book><Title>jQuery: Novice to Ninja</Title><Publisher>Site point</Publisher></Book>-<Book><Title>Learning jQuery</Title><Publisher>PACKT</Publisher></Book>-<Book><Title>Head First jQuery</Title><Publisher>O'Reilly</Publisher></Book>-<Book><Title>jQuery UI 1.8</Title><Publisher>PACKT</Publisher></Book></BookList>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question