无法从openWeatherMap api获取数据JavaScript
问题描述:
不知道问题出在哪里,但在选定的div中没有显示任何内容。无法从openWeatherMap api获取数据JavaScript
$(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
没有错误@ yuriy636。 – SenDjasni
您是否从您发布的代码以外的地方调用'getData()'?请张贴您的HTML。 – yuriy636