I realize that the code below if failing because message sets innerHTML before the second get returns, and I’ve read through a ton of articles dealing with asynchronous code, but am still unable to get it to work despite having spent a lot of time working on it.
If some kind soul has the patience to assist a relative noob, I could use some help in getting the below code working.
<script>
$(document).ready(function(){
$.get('/api/people', function(data) {
var message="this many: ";
$.each(data.Results, function(i, user){
$.get("/api/people/"+user.Id+"/followers",function(dataFollowers) {
message += dataFollowers.length+",";
});
});
document.getElementById("GGAPI").innerHTML = message;
});
});
</script>
<div id="GGAPI"> </div>