• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Can't load image again

I can't load an image using jquery. I have code that works on another page but it doesn't work on this particular page I'm using this code trying to load yankee staduim

$(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 teamLogo = $("<img/>").attr("src","http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/" + id + ".png");
        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:"default.gif";
        $("#imgBatterTeam").attr("src",url)
		  //$('body').css('background-image', 'url(\''+url+'\')');
		  //$("#imgStad").attr("src",url)
        }  


      });
     }
  });
});

Open in new window

Slugger.html
39096.xml
0
powerztom
Asked:
powerztom
  • 4
1 Solution
 
leakim971PluritechnicianCommented:
$("#team"+homeOrAway).append(teamLogo);

I found : vh="A"
So $("#team"+homeOrAway) become : $("#teamA")
That mean there's an element in the current page where the ID is : teamA
I CAN'T locate it.

If this element is not in the page you CAN'T APPEND/PUT your teamLogo inside
0
 
powerztomAuthor Commented:
How did you find vh=A ?
0
 
powerztomAuthor Commented:
The logo part was a mistake it should be in there. here is the code I don't understand same code works in one project and not in another.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
.tablecell 
body {
	
	background-color: #000;
}
.tablecell2 {
	background-attachment: fixed;
	
	background-repeat: no-repeat;
	background-position: center top;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
var xmlPath = '/xml/mlb/scores/real';
  var xmlGameID = '39096';
  var stadiums = {
	"wrigley field":"Wrigley Field.jpg",
	"comerica park":"Comerica Park.jpg" ,
	"yankee stadium":"yankeestadium.jpg" ,
	"citi field":"Citi Field.jpg" ,
	"angel stadium of anaheim":"Angel Stadium of Anaheim.jpg" ,
	"rangers ballpark in arlington":"Rangers Ballpark.jpg" ,
	"at&t park":"at&t park.jpg" ,
	"citizens bank park":"Citizens Bank Park.jpg" ,
	"coors field":"Coors Field.jpg" ,
	"busch stadium":"Busch Stadium.jpg" ,
	"oriole park at camden yards":"Camden Yards.jpg",
	"dodger stadium":"Dodger Stadium.jpg" ,
	"chase field":"Chase Field.jpg" ,
	"tropicana field":"Tropicana Field.jpg" ,
	"great american ball park":"Great American Ball Park.jpg" ,
	"kauffman stadium":"Kauffman Stadium.jpg" ,
	"mcafee coliseum":"mcafeecoliseum.jpg" ,
	"hubert h. humphrey metrodome":"metrodome.jpg" ,
	"metrodome":"metrodome.jpg" ,
	"miller park":"Miller Park.jpg" ,
	"minute maid park":"Minute Maid Park.jpg" ,
	"pationals park":"Nationals Park.jpg" ,
	"petco park":"Petco Park.jpg" ,
	"pnc park":"PNC Park.jpg" ,
	"progressive field":"Progressive Field.jpg" ,
	"rogers centre":"Rogers Centre.jpg" ,
	"safeco field":"Safeco Field.jpg" ,
	"turner field":"Turner Field.jpg" ,
	"dolphin stadium":"dolphinstadium.jpg" ,
	"fenway park":"Fenway Park.jpg" ,
	"u.s. cellular field":"U.S. Cellular Field.jpg" ,
	"oakland-alameda county coliseum":"OColiseum.jpg",
	"marlins park":"Marlins Park.jpg",
	
	 "minnesota":"Target Field.jpg"
}; // no comma on the last

var homeTurf = {
  "philadelphia":"citizens bank park",
  "milwaukee":"miller park",
  "san francisco":"u.s. cellular field",
  "la angels":"angel stadium of anaheim",
  "tampa bay":"tropicana field",
  "chicago wsox":"u.s. cellular field",
  "oakland":"oakland-alameda county coliseum",
  "kansas city":"kauffman stadium",
  "los angeles":"dodger stadium",
  "san diego":"petco park",
  "boston":"fenway park",
  "seattle":"safeco field",
  "detroit":"comerica park",
  "atlanta":"turner field",
  "baltimore":"oriole park at camden yards",
  "miami":"marlins park",
  "pittsburgh":"pnc park",
  "ny mets":"citi field",
  "st. louis":"busch stadium",
  "houston":"minute maid park",
  "cleveland":"progressive field",
  "cincinnati":"great american ball park",
  "texas":"rangers ballpark in arlington",
  "toronto":"rogers centre",
  "chicago cubs":"wrigley field",
  "arizona":"chase field",
  "colorado":"coors field",
  "ny yankees":"yankee stadium",
  "washington":"nationals park"
};
$(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)
        }  


      });
     }
  });
});
</script>
</head>

<body>
<table width="490" border="0">
  <tr>
    <td height="500"><p><img src="http://199.233.14.112/aspdata/mlb2/New/Staduimssmall/AT&T Park.jpg" alt="" name="imgStad" width="450" height="602" id="imgStad"></p></td>
  </tr>
</table>
</body>
</html>

Open in new window

0
 
powerztomAuthor Commented:
I screwed up the path I changed it to local and ballpark loaded correctly. I think i'm cool
but thanks for the help.
0
 
powerztomAuthor Commented:
I am great psych!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now