Solved

Duplicate score on NFL SCOREBOARD JQUERY XML HELP

Posted on 2013-06-06
3
545 Views
Last Modified: 2013-06-06
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
Comment
Question by:powerztom
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39226992
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
 

Author Closing Comment

by:powerztom
ID: 39227051
Thanks Rob for explanation I learning slowly but surely. Your the Best EE Guy seriously
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39227081
You're welcome and thanks for your kind words, I'm getting a double ego boost today.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now