Solved

Can't Load image for background and can't load batter image

Posted on 2013-06-26
5
258 Views
Last Modified: 2013-07-01
I can't load a image in a table and I have two apdivs for a right handed batter image or left handed batter image. This did work however something is off for the image in the table i'm loading a image into a image.

$(document).ready(function(){
  $.ajax({
    type: "GET",
    url: xmlPath+"/"+xmlGameID+".xml",
	
    dataType: "xml",
    success: function(data){
      var Teams = $(data).find("Team");
	  
      $.each(Teams,function(i,Team) {
        team=$(Team);
        var id = team.attr("ID").toLowerCase();
       
        var homeOrAway = team.attr("vh");
	var name = team.attr("name").toLowerCase();
       // $("#team"+homeOrAway).append(teamLogo);
        if (homeOrAway=="H") {
          var stadium_location = stadiums[homeTurf[name]]; // or have
          var url = "http://199.233.14.112/aspdata/mlb2/New/Staduimssmall/";
         
          url = (stadium_location) ?url + stadium_location:"AT&T Park.jpg";
				$("#imgStad").attr("src",url)
		  //$('body').css('background-image', 'url(\''+url+'\')');
		  //$("#imgStad").attr("src",url)
        }  


      });
     }
  });

Open in new window


This should load the batter I did but now it's not attached is the xml file which has necessary data


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


Can't figure this one out.
36845.xml
Slugger.html
0
Comment
Question by:powerztom
  • 3
5 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 39278859
On lines 16-18, try changing:
... ? picName : 'Players/Blank.gif'

to:
... ? picName : baseUrlBatterLR + 'Blank.gif'
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39278885
Does the actual path to an image display the image in a browser?

Example:

http://199.233.14.112/aspdata/mlb2/New/Players/BatterL12345.png

Add

alert(picName);

after line 15 to see if the value of picName is a valid URL.
0
 

Author Comment

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

Here is live look at Slugger Giants Staduim comes up Giants Staduim is the default it should load Marlins.jpg http://199.233.14.112/aspdata/mlb2/round3.html
http://199.233.14.112/aspdata/mlb2/index.html
0
 

Accepted Solution

by:
powerztom earned 0 total points
ID: 39279065
I screwed up I had the path set to local and not network so it works right. Thanks anyway!
0
 

Author Closing Comment

by:powerztom
ID: 39289418
I screwed up I had the path set to local and not network so it works right. Thanks anyway!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

803 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