Accessing images with javascript in struts
Friday afternoon and my brain is on the fritz again.
I'm using javascript/jquery to place markers in an instance of google maps. Just placing them with standard values works without a hitch but I want to use custom icons. My code looks something like this.var image = "/img/" + $(this).find('statusId').text()+".p开发者_C百科ng";
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: image
});
My images are the folder /img and are named 1.png, 2.png...
Without the "icon" parameter all works fine. My guess is that the script can't find the files and that Struts2 is to blame. Any suggestions on how to make this work?Edit: Moved the folder up one step in the hierarchy. I can now access the picture when I enter the adress in a browser wich I couldn't before. A call to marker.getIcon() returns the pathway to my file.
Use a full valid path (http://path.to/your/image instead of /path/to/img). This ensures that the path the API is getting is definitely to the image. Alternatively make very sure that the relative path to that image actually works by seeing where the request goes to when you put in the relative path (via the Net tab in Firebug, for example).
If you are worried about the full path changing, consider generating the Javascript on the server side with the full URL filled in by the server or passing a variable in from the server side that has the full URL so you aren't changing hard-coded values.
精彩评论