Solved

Can't load batter consecutively

Posted on 2013-06-26
5
260 Views
Last Modified: 2013-06-27
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
0
Comment
Question by:powerztom
  • 3
  • 2
5 Comments
 

Author Comment

by:powerztom
ID: 39279408
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
 
LVL 82

Expert Comment

by:hielo
ID: 39279652
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
 

Author Comment

by:powerztom
ID: 39281324
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
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 39281531
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
 

Author Closing Comment

by:powerztom
ID: 39282542
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

759 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

17 Experts available now in Live!

Get 1:1 Help Now