2016-12-30 102 views
0

我检查了链接,它完美地工作。这是我在控制台收到错误:

GET http://localhost:60789/api.openweathermap.org/data/2.5/weather?q=Tel%20Aviv%2CIL&units=metric&APPID=the给定数量的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); 
     }) 
    }); 
}); 
+0

GET请求清楚地显示了问题...有人没有使用绝对链接。 – epascarello

回答

4

你错过了在openWeatherMap URL的http://前缀。正因为如此,浏览器假设你提供的路径是相对于当前的URL,所以预规划http://localhost:60789/它 - 因此你404

要解决这个问题,简单地将http://的URL,使其绝对:

var openWeatherMap = 'http://api.openweathermap.org/data/2.5/weather'; 
+0

now iam get this: –

相关问题