问题描述
请我需要帮助我的人,我是jquery的新手,我将永远感谢您的帮助。 我有一个IP API,其中我将“城市”作为输出之一。我的目标是在openweather API中将其作为输入传递,并获取任何城市的天气。 尽管我从IP API获取输出,但从天气API中未获取任何数据,但始终收到此错误https://api.openweathermap.org/data/2.5/weather?q=undefinedundefined&`appid`=371f15346191ae114ca4ab11f4db4e2f错误响应] 1
这是我正在使用的代码,但到目前为止,我仅能成功地从IP API获取数据
// Weather
$(document).ready(function() {
var key = '3e4hxdke3eryjs';
$.ajax({
type: 'GET',url: 'https://api.ipregistry.co/'+ '?key=' + key,dataType: 'json',cache: true,success: function() {
var city = city;
var code = code;
var latitude = latitude;
var longitude = longitude;
console.log(city + ' ' + code + ' ' + latitude + ' ' + longitude);
console.log('success!');
$.ajax({
//url: "http://api.openweathermap.org/data/2.5/weather?q=Lagos,Nigeria&appid=371f15346191ae114ca4ab11f4db4e2f",url:"https://api.openweathermap.org/data/2.5/weather?q="+city+code+"&appid=371f15346191ae114ca4ab11f4db4e2f",success: function(data){
// [0 Kalvin = -273.15 Celsius] Conversion (k to c);
var cel=data.main.temp - 273.15;
$('#weatherName').html(data.name);
$('#weatherImg').attr('src','https://openweathermap.org/img/w/'+data.weather[0].icon+'.png');
$('#weatherCelsius').html(Math.round(cel) +'' + ' ℃');
$('#weatherCloudiness').html(data.weather[0].description);
}
});
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
使用openweather API获取城市的天气,您可以使用“ city”或/和两个字母的“国家/地区代码”作为输入参数,而这些参数都是从IP API给出的
谢谢大家的帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)