yahoo から API 経由で天気を取得したい。関数は まで起動しhtml
ます。alert
function の html の前に置きます。html
それが私に警告を表示する前のとき。しかし、それがhtml
機能しない後です。エラーがあることを示しhtml
ています。どうした ?
<script type="text/javascript">
$(document).ready(function () {
$.simpleWeather({
zipcode: '',
woeid: '@Html.DisplayFor(modelItem => item.zipcode)',
location: '',
unit: 'c',
success: function (weather) {
//html = '<h2>' + weather.city + ', ' + weather.region + '</h2>';
//html += '<img style="float:left;" width="125px" src="' + weather.image + '">';
alert("hi");
html += '<p>' + weather.temp + '° ' + weather.units.temp + '<br /><span>' + weather.currently + '</span></p>';
html += '<a href="' + weather.link + '">View Forecast »</a>';
$("#weather").html(html);
},
error: function (error) {
$("#weather").html('<p>' + error + '</p>');
}
});
});
</script>
アラートが機能するようになりました
しかし、このアラートでは機能しません:
<script type="text/javascript">
$(document).ready(function () {
$.simpleWeather({
zipcode: '',
woeid: '@Html.DisplayFor(modelItem => item.zipcode)',
location: '',
unit: 'c',
success: function (weather) {
html = '<h2>' + weather.city + ', ' + weather.region + '</h2>';
html += '<img style="float:left;" width="125px" src="' + weather.image + '">';
alert("hi");
html += '<p>' + weather.temp + '° ' + weather.units.temp + '<br /><span>' + weather.currently + '</span></p>';
html += '<a href="' + weather.link + '">View Forecast »</a>';
$("#weather").html(html);
},
error: function (error) {
$("#weather").html('<p>' + error + '</p>');
}
});
});
</script>
これは私のhtmlコードです:
<div id="weather"></div>
html
エラーがあります。お願い助けて 。