Can't load batter consecutively

I cannot load a batter reliably it loads sometimes but the link is below gamezone is the tab
 http://199.233.14.112/aspdata/mlb2/Page3.html
function loadData() {
    $.ajax({
      type: "GET",
      url: xmlPath+"/"+xmlGameID+".xml",
      dataType: "xml",
      success: function(data){
       
        //var intOuts = d.find('Play').attr("Outs") || 0;
        //$('#Outs').attr('src', arrStrikeImages[intOuts]);
        
		var baseUrlBatterLR = 'http://199.233.14.112/aspdata/mlb2/New/Players/'; // or some other directory you decide on
var d = $(data);
var Batter = $(d.find('Batter'));
var bat = Batter.attr("Bats");
var picName = baseUrlBatterLR + 'Batter' + bat + Batter.attr('TeamID') + '.png'; // so for team 12345 you need BatterL12345.png and BatterR12345.png
$('#batterLeft').attr('src', bat=="L" ? picName : 'Players/Blank.gif');
$('#batterRight').attr('src', bat=="R" ? picName : 'Players/Blank.gif');
$('#batterRight').attr('src', bat=="S" ? picName : 'Players/Blank.gif');
	 },

      error: function() {
      }

    });
  }

Open in new window

36459.xml
Slugger.html
powerztomAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
var BatterCount=-1;
function loadData(){
	BatterCount++;

	$.ajax({
		type: "GET"
		,url: xmlPath+"/"+xmlGameID+".xml"
		,dataType: "xml"
		,success: function(data){
		
			var baseUrlBatterLR = 'http://199.233.14.112/aspdata/mlb2/New/Players/'; // or some other directory you decide on
			var d = $(data);
			var limit=$(d.find('Batter')).size();
			var Batter = $(d.find('Batter:eq('+(BatterCount%limit)+')'));
			var bat = Batter.attr("Bats");
			var picName = baseUrlBatterLR + 'Batter' + bat + Batter.attr('TeamID') + '.png'; // so for team 12345 you need BatterL12345.png and BatterR12345.png

			switch(bat)
			{
				case 'R':
						$('#batterLeft').attr('src',baseUrlBatterLR + 'Blank.gif');
						$('#batterRight').attr('src', picName);
						break;

				case 'S':	/*I don't know what the 'S' stands for (which is in your code) but you should be able to customize it to suit your needs */
						$('#batterLeft').attr('src',baseUrlBatterLR + 'Blank.gif');
						$('#batterRight').attr('src', picName);
						break;

				case 'L':
						$('#batterLeft').attr('src', bat=="L" ? picName : baseUrlBatterLR + 'Blank.gif');
						$('#batterRight').attr('src',baseUrlBatterLR + 'Blank.gif');
						break;

				default:
						$('#batterLeft').attr('src',baseUrlBatterLR + 'Blank.gif');
						$('#batterRight').attr('src',baseUrlBatterLR + 'Blank.gif');
						break;
			}
		}
		,error: function() {
		}
	});
}

Open in new window

0
 
powerztomAuthor Commented:
Actually the naming convention for the batter is Batter+L+ "Left" Team id.png Team ID IS in xml. But First I gotta get the staduim to load. BatterL029.png
so http://199.233.14.112/aspdata/mlb2/New/Players/BatterL029.png
0
 
hieloCommented:
How did you arrive at the conclusion that you need to load BatterL029.png?

On the XML you attached, there is one <Batter> element with Bats="R" and TeamID="014".  So, initially, it should load "BatterR014.png" not "BatterL029.png".

Also, regarding "Can't load batter consecutively", what exactly do you mean?  Taken at face value, I would interpret that to mean that you can load the first <Batter> but not the subsequent ones.  If that is the case, then I would expect more than one <Batter> element.  In your XML you only have one, so only one keeps reloading every 5 seconds.  Where/How are you planning to retrieve the next Batter from?

If you add more <Batter> elements AND make the following changes you should see the players change.  When the last <Batter> element is reached, on the next call it would cycle back to the first one.

...
var BatterCount = -1;
function loadData() {
     BatterCount++;
...
var d = $(data);
var limit=$(d.find('Batter')).size();
var Batter = $(d.find('Batter:eq('+(BatterCount%limit)+')'));
var bat = Batter.attr("Bats");
...
0
 
powerztomAuthor Commented:
Sorry BatterL029.png is just a example not based on attached xml file. I got plans to ad player headshot for batter as well as stats and incoming pitch and result like Homerun Triple double strike out and walk. But I just need a batter to load constantly and not disappear.
0
 
powerztomAuthor Commented:
This guy went the extra mile for this to work. I'm Happy cause I thought it couldn't be done but this guy hielo deserves alot of credit. Great Work.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.