Skip to content

Instantly share code, notes, and snippets.

@psycalc
Last active June 30, 2016 06:04
Show Gist options
  • Save psycalc/cb052e8300fb619e78fafc67fad3b0f6 to your computer and use it in GitHub Desktop.
Save psycalc/cb052e8300fb619e78fafc67fad3b0f6 to your computer and use it in GitHub Desktop.
Example weather of using api by javascript
$.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