Solved

Can't load image again

Posted on 2013-06-19
5
202 Views
Last Modified: 2013-06-25
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
Comment
Question by:powerztom
  • 4
5 Comments
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
$("#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
 

Author Comment

by:powerztom
Comment Utility
How did you find vh=A ?
0
 

Author Comment

by:powerztom
Comment Utility
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
 

Accepted Solution

by:
powerztom earned 0 total points
Comment Utility
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
 

Author Closing Comment

by:powerztom
Comment Utility
I am great psych!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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 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)

771 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

10 Experts available now in Live!

Get 1:1 Help Now