I'm looking for a solution to ensure that the three functions that I created run in an ordered sequrence once the first has completed.
Currently I have something like this which does not seem to work at all.
$(document).ready(function() {
$.when(runPending(selectedYear, name)).then(runApproved(selectedYear,name)).then(runRejected(selectedYear,name));
});
function runPending(year, name){
var deferred = new jQuery.Deferred();
$.getJSON(URL, function() {
}).done(function(json) {
if(json.length == 0){
console.log("No Data came back!");
}
else{
//do stuff set to html_output_pending;
$('#display').append(html_output_pending);
}//end else
}).fail(function(xhr, status, error) {
alert(xhr.responseText);
});
return deferred.promise();
}
function runApproved(year, name){
var deferred = new jQuery.Deferred();
$.getJSON(URL, function() {
}).done(function(json) {
if(json.length == 0){
console.log("No Data came back!");
}
else{
//do stuff set to html_output_pending;
$('#display').append(html_output_pending);
}//end else
}).fail(function(xhr, status, error) {
alert(xhr.responseText);
});
return deferred.promise();
}
function runRejected(year, name){
var deferred = new jQuery.Deferred();
$.getJSON(URL, function() {
}).done(function(json) {
if(json.length == 0){
console.log("No Data came back!");
}
else{
//do stuff set to html_output_pending;
$('#display').append(html_output_pending);
}//end else
}).fail(function(xhr, status, error) {
alert(xhr.responseText);
});
return deferred.promise();
}
How do I ensure that once runPending has been completed and appended its data to the div element #display, execute the second function in order to the third.
Any help on this would be greatly appreciated!
Thank you.
asyncflag tofalsebut it might be a better idea if you attach the functions you need to the success handlers of each.getJSONdoes not have anasyncflag. You would need to add them to the success handler.