我检查了链接,它完美无缺 . 这是我在控制台中遇到的错误:
GET http:// localhost:60789 / api.openweathermap.org / data / 2.5 / weather?q = Tel%20Aviv%2CIL&units = metric&APPID =给定数字404(未找到)
$(document).ready(function () {
var getIP = 'http://ip-api.com/json';
var openWeatherMap = 'api.openweathermap.org/data/2.5/weather'
$.getJSON(getIP).done(function(location) {
$.getJSON(openWeatherMap, {
q: location.regionName + "," + location.countryCode,
units: 'metric',
APPID: 'Here iam giving my appid'
}).done(function (weather) {
console.log(weather);
$('ul:first-child').html(weather.name + "," + weather.sys.country);
})
});
});
1 回答
你错过了
openWeatherMap
网址上的http://
前缀 . 因此,浏览器假定您提供的路径是相对于当前URL的,因此预先设置http://localhost:60789/
- 因此您的404 .要解决此问题,只需将
http://
添加到URL以使其成为绝对值: