我是javascript的新手,我正在努力解决整个回调和异步问题。我有一个名为'RunJob'的函数,它多次执行另一个名为'GetData'的函数。在这些函数完成执行之后,我希望进行更多处理,但直到这些函数完成。我怎么能这样做?
//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
}