Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First off, the way that I know how to parse these using jQuery will give problems with the <code>image</code> tag (<strong>edit:</strong> only if you parse text; XML turns out to be fine), as once you wrap it in jQuery it will convert <code>&lt;image&gt;text&lt;/image&gt;</code> to <code>&lt;img&gt;text</code>. You can deal with that, but it's not pretty. So let's assume you've renamed <code>&lt;image&gt;</code> to <code>&lt;cover&gt;</code>.</p> <p>Working <a href="http://jsfiddle.net/jdLhR/4/" rel="nofollow">jsFiddle</a>, minus the <code>$.ajax</code> request part.</p> <pre><code>var music = []; var musicIndex = -1; var delay = 5000; var intervalId; // in case you want to clearInterval var $cover = $("#albumcover"); var $desc = $("#songdescription"); function rotateMusic() { // Loop back to the beginning if necessary if (++musicIndex === music.length) { musicIndex = 0; } console.log(music[musicIndex].cover); // Create a new image, tell it to append itself and description // once it's loaded, tell it to load $("&lt;img&gt;").load(function() { $cover.empty().append($(this)); $desc.text(music[musicIndex].desc); }).attr("src", music[musicIndex].cover); } $.ajax({ type: "GET", url: "music.xml", dataType: "xml", success: function(xml) { // Parse each item as a node $(xml).find('item').each(function() { // Add contents of item to music array var $item = $(this); music.push({ cover: $item.find('image').text(), desc: $item.find('description').text() }); }); // Start rotating music, then set it to a delay rotateMusic(); intervalId = setInterval(rotateMusic, delay); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload