I'm trying to use OpenWeatherMap and get the JSON for the weather. In the console i see 404 message, but when i visit the url manually it gives me the correct JSON
var latitude;
var longitude;
var apiId = "c440e3f473378f9705827ed71efe5dcc";
var request = new XMLHttpRequest();
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function getPosition(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
getJson();
});
} else {
alert('Geo location not working or not supported by your browser.');
}
}
function getJson() {
request.open('GET', "api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&APPID=" + apiId + "");
request.onload = function(data) {
console.log(data);
};
request.send();
}
getLocation();
http://
orhttps://
or perhaps evenwww
.https://
orhttp://
in beginning of every link, or else it'll just assume it to befile:///
by default.