Solved

Can't load batter consecutively

Posted on 2013-06-26
5
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
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…

740 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