I'm working through free code camp and trying to build a weather app using OpenWeatherMap API but It's not working. I'm using codepen because that's what it needs to be submitted on and it has to be a https to use geo location. This has become a problem because I get this error.
Mixed Content: The page at 'https://s.codepen.io/boomerang/8658fc75197c1c3799d7eb446c1be54c1475174843341/index.html?editors=0010' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.openweathermap.org/data/2.5/weather?lat=54.757753799999996&lon=-1.6074879&APPID=APIIDHERE'. This request has been blocked; the content must be served over HTTPS.
For some reason I thought it might work if I change the API call to HTTPS but then I get this error
GET https://api.openweathermap.org/data/2.5/weather?lat=54.757775699999996&lon=-1.6074815999999998&APPID=APIIDHERE net::ERR_CONNECTION_REFUSED
I have used an api key but i've just hidden it on here.
I've tried a few different ways of fixing it i've seen on other posts but nothing has worked so far :/
I'm using this code for the request
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 ();
}
Any help would be appreciated :)