我正在通過免費代碼陣營並嘗試使用OpenWeatherMap API構建天氣應用程序,但它不起作用。我正在使用codepen,因爲這是它需要提交的內容,它必須是使用地理位置的https。這已成爲一個問題,因爲我得到這個錯誤。OpenWeatherMap API HTTPS拒絕javascript
混合內容:在「https://s.codepen.io/boomerang/8658fc75197c1c3799d7eb446c1be54c1475174843341/index.html?editors=0010」加載頁面通過HTTPS,但要求一個不安全的XMLHttpRequest端點「http://api.openweathermap.org/data/2.5/weather?lat=54.757753799999996&lon=-1.6074879&APPID=APIIDHERE」。此請求已被阻止;內容必須通過HTTPS提供。
出於某種原因,我想如果我改變API調用HTTPS但後來我得到這個錯誤
得到它可能工作https://api.openweathermap.org/data/2.5/weather?lat=54.757775699999996&lon=-1.6074815999999998&APPID=APIIDHERE網:: ERR_CONNECTION_REFUSED
我已經使用了API鍵,但我只是隱藏在這裏。
我試圖修復它的我已經看到了其他職位幾種不同的方法,但到目前爲止沒有奏效:/
我使用這個代碼請求
function updateLoc (lat, long) {
var url = "https://api.openweathermap.org/data/2.5/weather?" +
"lat=" + lat +
"&lon=" + long +
"&APPID=" + APPID;
sendRequest (url);
}
function sendRequest (url) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {
var data = JSON.parse (xmlhttp.responseText);
var weather = {};
weather.icon = data.weather.icon;
weather.dir = data.wind.deg;
weather.wind = data.wind.speed;
weather.temp = data.main.temp;
weather.loc = data.name;
weather.hum = data.main.humidity;
update (weather);
}
};
xmlhttp.open ("GET", url, true);
xmlhttp.send();
}
任何幫助將不勝感激:)
我寫了一個解決這個(這裏),他們將被視爲(HTTPS ://stackoverflow.com/questions/38659464/jquery-ajax-call-with-openweathermap-neterr-connection-refused/44900102#44900102) – Pila