我认为这是我的愚蠢而且问题非常轻微,但在获得请求后它并没有显示任何内容。我没有错误,我得到200回程。所以请求中的一切似乎都没问题。
if('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(function(position){
loadWeather(position.coords.latitude + ',' + position.coords.longitude);
});
} else {
loadWeather('Berlin, DE', '');
}
function loadWeather(location, woeid) {
$.simpleWeather ({
location: location,
woeid: woeid,
unit: 'c',
succes: function(weather) {
city = weather.city;
temp = weather.temp + '°';
wcode = '<img class="weathericon" src="assets/weatherimg' + weather.code + '.svg">';
wind = '<p>' + weather.wind.speed + '</p><p>' + weather.units.speed + '<p>';
humidity = weather.humidity + ' %';
$('.location').text(city);
$('.temperature').html(temp);
$('.climate_bg').html(wcode);
$('.windspeed').html(wind);
$('.humidity').text(humidity);
},
error: function(error) {
$('.error').html('<p>' + error + '</p>');
}
});
};
$(document).ready(function() {
loadWeather();
});
这是我的HTML代码。
<section>
<div class='mainContentHeader'>
<h2> Weather App </h2>
</div>
<div class='mainContent'>
<div class='container'>
<p class='location'></p>
<p class='temperature'></p>
<div class='climate_bg'>
</div>
<div class='info_bg'>
<img class='dropicon' src='/assets/Droplet.svg'>
<p class='humidity'></p>
<img class='windicon' src='/assets/Wind.svg'>
<div class='windspeed'></div>
</div>
</div>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery.simpleWeather/3.1.0/jquery.simpleWeather.min.js'> </script>