Created
May 19, 2018 21:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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