2016-08-26 18 views
0

error
私は天気アプリを構築しています、と私はAPIを呼び出すときに、$.getJSONは私のローカルホストADDRESを追加します。

http://localhost:3000/api.openweathermap.org/data/2.5/weather?lat=50.064650099999994&lon=19.9449799&APPID=f7dcb8e5d6a1f2126a2080a1e0d17b5a 404(見つかりません)

$("#getLocation").on("click", function() { 
    if (navigator.geolocation) { 
     navigator.geolocation.getCurrentPosition(function(position) { 
      $("#location").html("latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude); 
      lat = position.coords.latitude; 
      lon = position.coords.longitude; 

      api = "api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=f7dcb8e5d6a1f2126a2080a1e0d17b5a"; 

      console.log(api); 

      $.getJSON(api, function(json) { 
       $("#api").html(json); 
      }); 
     }); 
    } 

}); 

答えて

0

GET URLは//servernameが含まれていないので、それは現在のページのパスからの相対URLとして解釈されます。用途:

 api = "//api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&APPID=f7dcb8e5d6a1f2126a2080a1e0d17b5a"; 
+0

おかげで、残念ながらドキュメントは、URL上の任意のまともなチュートリアルでは、彼らが構築している方法を説明しなければならない – KAT

+0

十分に明確ではありません。 – Barmar

関連する問題