[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

Duplicate score on NFL SCOREBOARD JQUERY XML HELP

I have a Nfl Scoreboard and I have it run through a complete set of xml game files. The problem is the same score comes up for visitor and hometeam. But i use a if statement

like this if ($(Team).attr('vh') == "A") {
and then
if ($(Team).attr('vh') == "H") {

Just hardcode attached xml file

 function loadData() {
    $.ajax({
      type: "GET",
      url:  xmlPath+"/"+xmlGameID+'_'+counterXml+".xml",
      dataType: "xml",
      success: function(data){
        var d = $(data);
        d.find('Team').each(function(i,Team){
          if ($(Team).attr('vh') == "A") {
            $('#imgVisitHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_away.png");
		  }
          if ($(Team).attr('vh') == "A") {
		  var VS1 = $(d.find('Team')).find('Linescore');
		  var vs2 = VS1.attr('Score');
		  $('#VS').html(vs2);}
          if ($(Team).attr('vh') == "H") {
            $('#imgHomeHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_home.png");
         }
		 if ($(Team).attr('vh') == "H") {
		   var HS1 = $(d.find('Team')).find('Linescore');
		  var hs2 = HS1.attr('Score');
		  $('#HS').html(hs2); 
		 }
        });
        var Play = $(d.find('Play'));
        // changed all below to just use the variables that contain the text directly, as the arrays do not exist and don't seem necessary in this situation
		
		var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
        var inn = Play.attr('TimeLeft') ;
        $('#Time').html(inn ); // timeleft[inn]
        var bo = Play.attr('BallYrd') ;
        $('#Ballon').html(bo ); // ballyrd[bo]
        var dn = Play.attr('ResultingDown') ;
        $('#Down').html(dn ); // resultingdown[dn]
        var ydtogo = Play.attr('ResultingToGo') ;
        $('#Ydstogo').html(ydtogo ); // resultingtogo[ydtogo]
        var qtr = Play.attr('Quarter') ;
        $('#Q').html(qtr ); // quarter[qtr]
        ++counterXml;
      }
    });
  }
</script>

Open in new window

Top.html
AB-3171-120.xml
0
powerztom
Asked:
powerztom
  • 2
1 Solution
 
Robert SchuttSoftware EngineerCommented:
On line 8 a loop is started which is executed twice because there are always 2 <Team> nodes in the xml files. In the existing code, inside the loop, $(Team) is used to refer to each respective node for which the loop is being executed.

In the new code, on lines 13 and 20, you repeat the code $(d.find('Team')), which does a new find() on the original data and will refer to the first <Team> node each time. So that should be replaced by $(Team) like this:
var VS1 = $(Team).find('Linescore');

Open in new window

and
var HS1 = $(Team).find('Linescore');

Open in new window

0
 
powerztomAuthor Commented:
Thanks Rob for explanation I learning slowly but surely. Your the Best EE Guy seriously
0
 
Robert SchuttSoftware EngineerCommented:
You're welcome and thanks for your kind words, I'm getting a double ego boost today.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now