New to jQuery. Having a recursion issue.

New to jQuery. Having a recursion issue.

Alright, I'm fairly new to jQuery, and what I'm asking for may not even be possible.

I have a very small XML file that looks like this:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <BookList>
  3. <Book>
  4. <Title>Book One</Title>
  5. <Publisher>Just A Test</Publisher>
  6. </Book>
  7. <Book>
  8. <Title>Book Two</Title>
  9. <Publisher>Some Other Book</Publisher>
  10. </Book>
  11. </BookList>

Just something simple, as proof of concept.

And this is the jQuery I'm using.

  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  5. <script>
  6. $(document).ready(function(){
  7. recurse();
  8. });

  9. function recurse(){
  10. $("#dvContent").appendTo("<ul></ul>");
  11. $.ajax({
  12. type: "GET",
  13. url: "BookList.xml",
  14. datatype: "xml",
  15. success: function(xml){
  16. $(xml).find('Book').each(function(){
  17. var sTitle = $(this).find('Title').text();
  18. var sPublisher = $(this).find('Publisher').text();
  19. $("<li></li>").html(sTitle + ", " + sPublisher).appendTo("#dvContent ul");
  20. });
  21. recurse();
  22. },
  23. error: function(){
  24. alert("An error occurred.");
  25. }
  26. });
  27. }

  28. recurse();

  29. </script>
  30. </head>
  31. <body>
  32. <h1>Some sort of test.</h1>
  33. <div id="dvContent"></div>
  34. </body>
  35. </html>

When I run this locally, it simply just creates a long bulleted list down the page. I understand why it's doing that, but I don't know how to fix it.

I'm just curious if I can build a near real-time solution without using some sort of plug-in or a timeout.

Essentially, what I want to do is change the XML file, and when I save it, the jQuery detects the change and immediately updates the results. So right now, I'd want to see two, and only two, bullet points. If I added a 3rd entry, I'd then want to only see three.

Don't know if  this is possible. I'm just curious if it can be done, and what I'm missing if it actually can. And if it can be done, what the repercussions are. The main one I can see is bandwidth, constantly hitting the server.

Thanks in advance!