I know this question has been asked several times, however I can't seem to get the solutions to work with my code: Wait till a Function with animations is finished until running another Function, jquery wait for multiple complete events, Wait for the end of TWO asynchrounous functions before firing a third (jQuery Deferred ?)
Basically, I would like to call four functions successively:
#1
function getJason() {
$.getJSON(rgUrl1,function(json1){
rgJson1 = json1; ...etc.
});
#2
function combineJason() {
//code to combine
});
#3
function divideArray() {
//code to divide stuff
});
#4
function doOtherStuff() {
//code to do some other stuff
});
I need #1 to finish before calling #2, #2 to finish before #3, and #3 to finish before #4. Past posts have led me to believe that I should use deferrds and promises. I've read through the documentation http://api.jquery.com/category/deferred-object/ and have experimented with examples without success:
function testing() {
var deferredObj = $.Deferred();
var test = getJson()
var function1 = function () {
test.done(function(){
deferredObj.resolve();
return deferredObj;
});
}
deferredObj.done(function(){
combineJson();
});
};
Furthermore, most of the examples deal with two functions, whereas I need to call several. I've also noticed that some responses incorporate "setTimeout". I'm a bit leery, perhaps unnecessarily, about using anything with a timer or pause or delay. Wouldn't I then have to guess how long the function will take. What about if one user's computer/connection is slower or something?