私は無料のコードキャンプを使って作業していて、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経由でコンテンツを配信する必要があります。私はHTTPSへのAPI呼び出しを変更した場合、それがうまくいくかもしれないと思ったいくつかの理由
が、その後、私はこのエラーを取得する
はhttps://api.openweathermap.org/data/2.5/weather?lat=54.757775699999996&lon=-1.6074815999999998&APPID=APIIDHEREネット:: ERR_CONNECTION_REFUSED
私が使用しているのGET 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