Parse Image From Json
http://api.wunderground.com/api/102376e7c0e1c995/geolookup/conditions/q/IA/Cedar_Rapids.json This is .json file to get the weather condition in Cedar Rapids, IA. In this json file
Solution 1:
As the last line of your script, add:
$("#meteo").append('<img src="' + wicon + '"/>");
Solution 2:
Just create an img tag that has the correct src attribute.
$( '<img>' ).attr( 'src', wicon ).appendTo( '#meteo' );
Solution 3:
Put an image element on the page (say with id Image1), then:
success: function (parsed_json)
{
var location = parsed_json['location']['city'];
var temp = parsed_json['current_observation']['temperature_string'];
var wicon = parsed_json['current_observation']['icon_url'];
$("#meteo").text(temp);
$("#Image1").attr("src", wicon);
}
Solution 4:
Please add an image tag that with the right attr.
$( '<img>' ).attr( 'src', wicon ).appendTo( '#meteo' );
Check out yourself: http://jsfiddle.net/dAz2p/
Solution 5:
You just need to assign wicon
to the src
property of your placeholder image
Edit: Code, as requested.
First of all, put a placeholder image where you want to display the final icon:
...
<img id='meteo_icon' src='meteo_loading.png'>
<h1 id='meteo'></h1>
...
Then, when assigning the text, also assign the src:
...
$("#meteo").text(temp);
$("#meteo_icon").attr("src", wicon);
...
Post a Comment for "Parse Image From Json"