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
Solved

Can't load image again

Posted on 2013-06-19
5
207 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
ID: 39260873
$("#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
ID: 39262674
How did you find vh=A ?
0
 

Author Comment

by:powerztom
ID: 39262701
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
ID: 39262751
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
ID: 39274161
I am great psych!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
$q.all is slower or not  in  Angularjs 2 21
Html Table looping 4 25
jQuery on Submit 4 36
on window close, not beforeunload 6 15
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

792 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