Skip to content

Instantly share code, notes, and snippets.

@xilikas
Created May 19, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xilikas/e193e27673956ada1c8a91631b9e3273 to your computer and use it in GitHub Desktop.
Save xilikas/e193e27673956ada1c8a91631b9e3273 to your computer and use it in GitHub Desktop.
Ajax Function for getting weather from FCC Weather API (https://fcc-weather-api.glitch.me) using longitude and latitude passed in as arguments.
function getWeather(latitude, longitude) {
$.ajax({
type: 'GET',
url: 'https://fcc-weather-api.glitch.me/api/current?lat='
+ latitude + '&lon=' + longitude,
async: false,
contentType: "application/x-www-form-urlencoded",
cache: false,
dataType: 'json',
success: function(data)
{
place = data.name + ", " + data.sys.country;
tempCel = data.main.temp;
condition = data.weather.main;
$("#location").html(place);
$("#weatherDegrees").html(tempCel + "C°");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("Ajax fail");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment