2016-07-29 33 views
1

我想根據經緯度擺脫OpenWeatherMap API天氣,但我發現了錯誤jQuery的AJAX調用與OpenWeatherMap - 網:: ERR_CONNECTION_REFUSED

net::ERR_CONNECTION_REFUSED

項目是codepen.io

var appid = "myID"; 

function getLocation() { 
    $.getJSON('https://geoip-db.com/json/geoip.php?jsonp=?') 
     .done (function(location) 
     { 
      $('.country').html(location.country_name); 
      $('.city').html(location.city); 
      var lat = location.latitude; 
      var lon = location.longitude; 
      var weatherLink = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=" + appid + "&callback=?"; 
      $('body').append(weatherLink); 
      $.ajax({ 
       url: weatherLink, 
       dataType: "jsonp", 
       success: function(response) { 
        $('body').append(response); 
       } 
      }); 
     }); 
} 

$(document).ready(function() { 
    getLocation(); 
}); 

我使用https://geoip-db.com/來獲取經度和緯度。 URL(weatherLink)是正確的。全錯誤:

GET https://api.openweathermap.org/data/2.5/weather?lat=51.1&lon=17.0333&appid= …0b9873ed&callback=jQuery22406914555127333375_1469796455615&_=1469796455617 net::ERR_CONNECTION_REFUSED

+0

這是一個低級別的套接字錯誤。 –

+0

我能做些什麼呢? – gkopowski

+0

問openweathermap,不在這裏。 –

回答

0

您的APPID有誤,只需註冊一個帳戶並從網站獲取密鑰。你需要一個有效的ID或它會拒絕你的連接。

http://openweathermap.org/appid#get

聯繫我您的codepen,我可以仔細看看,如果你願意的話。另外,如果你想從網站追加信息,你需要指定你想要的參數,否則你會得到一堆廢話。

+0

我有有效的ID,但我已經改爲「我的ID」來顯示我的代碼。這裏是codepen https://codepen.io/gkopowski/pen/JKBXxa – gkopowski

+0

其工作正常,最新的問題是什麼? –

+0

再次看,有一個$ .ajax調用,在控制檯產生錯誤 – gkopowski