I'm a newbie to javascript and I'm struggling with the whole callback and asynchronous thing. I have a function called 'RunJob' which executes another function called 'GetData' several times. After these functions have finished executing I wish to do some more processing, but not until the those functions have finished. How can I do this?
//a button with 'RunJob()' as the onclick event
function RunJob() {
ProcessData(GetData, "condition1");
ProcessData(GetData, "condition2");
ProcessData(GetData, "condition3");
//More processing when the ajax calls in 'GetData' have finished
}
function ProcessData(callback, myVariable) {
callback(myVariable);
}
function GetData(myVariable) {
//Multiple ajax calls which will take a while
}