tags:

views:

34

answers:

2

I'm trying to build a player for a radio station that automatically updates the current song from an XML file, the problem is that I don't want it to update the UI (updateSongIMG) unless the song has actually changed. I have a hidden div called settings_songid that stores the song id and it should check that against a value in the XML file, if its different, then it should update it. The problem is that the function below does not actually work, it pulls all the XML data fine, but it doesn't call updateSongIMG as it fails the 'if'.

function loadXML() {
    $.get('player.xml', function(d){
        $(d).find('onair').each(function(){
            var $onair = $(this); 

            var show_name = $onair.find('showname').text();
            var song_l1 = $onair.find('songline1').text(); 
            var song_l2 = $onair.find('songline2').text();  
            var song_img = $onair.find('songimg').text(); 

            var song_id = $onair.find('song_id').text(); 
            var old_song_id = $("#settings_songid").html();

            if (!old_show_id==show_id){
                $("#settings_songid").html(song_id);

                updateSongIMG(song_img,song_l1,song_l2);
            }
        });
    });
};
​
+2  A: 

Where are these defined old_show_id and show_id ?!

You can use http://api.jquery.com/jQuery.data/ for that kind of stuff.

Ivo Sabev
+1 for `jQuery.data` suggestion.
prodigitalson
`jQuery.data` is awesome. +1 I didn't even look at how he was grabbing the data.
Vivin Paliath
A: 

Try .text():

 var old_song_id = $("#settings_songid").text();

and your if clause is wrong. I think you mean song and not show:

if(old_song_id != song_id)

For storing arbitrary data, have a look at jQuery's .data() method. This much more convenient than storing data in a hidden div.

Felix Kling