Last active
April 21, 2016 16:54
-
-
Save csessig86/014bc5e095c5622598a00f5bd0ecdde9 to your computer and use it in GitHub Desktop.
Making two AJAX calls
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
// Holds data for each AJAX call | |
var global_data = {}; | |
var global_data_two = {}; | |
// Put data on Leaflet map | |
function leafletMap() { | |
console.log('Leaflet map creation here'); | |
} | |
// Do the merge of the data here | |
function mergeData() { | |
console.log('global_data:'); | |
console.log(global_data); | |
console.log('global_data_two:'); | |
console.log(global_data_two); | |
console.log('merge data here'); | |
leafletMap(); | |
} | |
// Both AJAX calls happen within this function | |
function ajaxCall(iteration_num, ajax_url) { | |
$.ajax({ | |
type: "GET", | |
dataType: "json", | |
url: ajax_url, | |
success: function(data){ | |
if (iteration_num === 0) { | |
global_data = data; | |
} else { | |
global_data_two = data; | |
} | |
}, | |
complete: function() { | |
if (iteration_num === 0) { | |
ajaxCall(1, 'https://datagetter.herokuapp.com/arrests.json') | |
} else { | |
mergeData(); | |
} | |
} | |
}); | |
} | |
ajaxCall(0, 'https://datagetter.herokuapp.com/arrests.json'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment