我正在通过免费代码阵营并尝试使用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