Fun with Open Weather Map API & named callbacks
JavaScript
function getMI(callback) {
var milink = 'http://static.mcclatchyinteractive.com/migap/TheState/117.json?callback=';
$.ajax({
dataType: "json",
url: milink,
success: function(data) {
console.log("anonymous funct:", data);
}
});
}
// get data:
getMI(function (data) {
console.log('mi data received');
console.log(data);
});
function getWeather(callback) {
var weather = 'http://openweathermap.org/data/2.1/find/city?lat=13.3428&lon=-6.26612&cnt=10';
$.ajax({
dataType: "jsonp",
url: weather,
success: callback
});
}
// get data:
getWeather(function (data) {
console.log('weather data received');
console.log(data.list[0].weather[0].description);
});