【发布时间】:2016-07-31 13:13:18
【问题描述】:
不知道问题出在哪里,但在 div selected 中没有显示任何内容。
$(document).ready(function(){
var lat, lng, data;
// get the current location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
});
}else {
alert('Geo Location feature is not supported in this browser.');
}
//get the data from the openWeatherMap API
function getData(){
$.getJSON('api.openweathermap.org/data/2.5/weather?lat='+lat+'&lon='+lng+'', function(json){
data = json;
});
}
$('button').on('click', function(){
getData();
$(this).remove();
$('.container').removeClass('hidden');
$('#location').appendTo(data.name);
$('#Weather-condition').appendTo(data.weather.main);
$('#wind-speed').appendTo(data.wind);
});
});
【问题讨论】:
-
您检查控制台是否有任何错误?
-
没有错误@yuriy636。
-
您是否从您发布的代码以外的其他地方调用
getData()?请也发布您的 HTML。 -
是的,我忘记调用它,但是当我这样做时,什么也没发生codepen.io/sendja/pen/xOYbvr 这是我正在开发的应用程序。
-
您知道必须使用 API 密钥才能从 openweathermap 请求数据吗?
标签: javascript jquery web-applications