jQuery addClass example
Change class name on click in jQuery
by D S
JavaScript
var stationInfo, stationHistory, itunesInfo, coverInfo; // to store the returned JSON data
var station_data, history_data, itunes_data, coverList_data; // set by _cacheOptions
// wait for getJSONs to resolve
$.when(parseJSON1, parseJSON2)
// use resolved data in next step
.then(function(JSON1, JSON2) {
// set your scoped vars
stationInfo = JSON1;
stationHistory = JSON2;
// Then call the next two async fetches
// Note that, since you already set your local vars with the returned data,
// you don't need to pass anything to these functions, they can just
// reference the info like the _cachOptions function
return $.when(parseJSON3("dan"), parseJSON4());
})
.then(function(JSON3, JSON4) {
// set your scoped vars
itunesInfo = JSON3;
coverInfo = JSON4;
return _cacheOptions();
})
// Core Functions
function _cacheOptions() {
station_data = stationInfo[0];
history_data = stationHistory[0];
itunes_data = itunesInfo[0];
coverList_data = coverInfo[0];
console.log(itunes_data)
}
function parseJSON1() {
return $.getJSON(JSON1ss);
}
function parseJSON2() {
return $.getJSON(JSON2ss);
}
function parseJSON3(searchTerm) {
return $.getJSON(JSON3ss);
}
function parseJSON4() {
return $.getJSON(JSON4ss);
}
var JSON1ss = "https://api.myjson.com/bins/t5vh1";
var JSON2ss = "https://api.myjson.com/bins/1hkn9x";
var JSON3ss = "https://api.myjson.com/bins/bynt1";
var JSON4ss = "https://api.myjson.com/bins/iifgl";