Solved

Duplicate score on NFL SCOREBOARD JQUERY XML HELP

Posted on 2013-06-06
3
557 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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)

785 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