Last active
June 30, 2016 06:04
-
-
Save psycalc/cb052e8300fb619e78fafc67fad3b0f6 to your computer and use it in GitHub Desktop.
Example weather of using api by javascript
This file contains hidden or 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
$.ajax({ | |
url: 'https://simple-weather.p.mashape.com/weatherdata?lat=' + coords[0] + '&lng=' + coords[1], | |
type: 'GET', | |
dataType: 'json', | |
success: function(data) { | |
console.log(data.query.results.channel.item.condition.temp); | |
var unit = data.query.results.channel.units.temperature; | |
$(".country").html(data.query.results.channel.location.country); | |
$(".city").html(data.query.results.channel.location.city); | |
$(".weather").html(data.query.results.channel.item.condition.text); | |
$(".temperature-text").html(data.query.results.channel.item.condition.temp + " °" + unit); | |
weather = data.query.results.channel.item.condition.text; | |
}, | |
error: function(err) { | |
console.log(err); | |
$('.inner-container').html('data for location does not exist'); | |
}, | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader("X-Mashape-Authorization", 'API_KEY_GENERATED_BY_API_PROVIDER'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment