S
S
Stels0072017-09-26 20:21:31
JavaScript
Stels007, 2017-09-26 20:21:31

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.");
  }
  });
});


Database
<?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>


When I run the code, I get the error "An error occurred while processing XML file." Given that the database file is not broken (Lies at the root next to Index.html), then why are there problems with opening? Or problems with something else? Or maybe I'm not connecting something correctly ...
PS I'm new to jQuery, so I'm asking for help to figure it out, perhaps with elementary concepts. I hope for your experience, senior comrades)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question