Last active
December 25, 2017 17:21
-
-
Save elinwibe/2c441ec65ca5e8744adcf85927e00a6e to your computer and use it in GitHub Desktop.
Lewisham Air Quality measurement from King's College API
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
var sitecode = "LW4" | |
var URL = "http://api.erg.kcl.ac.uk/AirQuality/Daily/MonitoringIndex/Latest/SiteCode=" + sitecode + "/Json"; | |
console.log('Fetching air quality data from-' + URL); | |
function processResult(data) { | |
var LAsite_data = data.DailyAirQualityIndex.LocalAuthority; | |
console.log(data); | |
console.log(LAsite_data.Site['@SiteName']); | |
console.log(LAsite_data.Site.Species[0]['@AirQualityBand']); | |
} | |
$.getJSON(url, processResult); |
Try this instead
`var sitecode = "LW4"
var URL = "http://api.erg.kcl.ac.uk/AirQuality/Daily/MonitoringIndex/Latest/SiteCode=" + sitecode + "/Json";
$.ajax({
url: URL,
type: "GET",
crossDomain: true,
dataType: "json",
success: function(response) {
console.log(response);
processResult(response);
},
error: function(xhr, status) {
alert("error");
}
});
function processResult(data) {
var LAsite_data = data.DailyAirQualityIndex.LocalAuthority;
console.log(LAsite_data.Site['@Sitename']);
console.log(LAsite_data.Site.Species[0]['@AirQualityBand']); //path was given in Json
}`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Think you had a type on line 12 Species - instead of species :-)