I have 2 functions.
function f1() {
$.ajax(..., success: function(response) {
// some code executed whenever request is completed.
}
}
function f2() {
// my code
}
I need to call these functions one after another.
f1() // waiting until ajax request in the function is complete.
f2()
I tried $.when().then(), however it didn’t seem to work.
The
$.ajaxcall returns an instance of$.Deferredwhich is used to track the progress of the call – that is what you need to return from yourf1function. You can then use.then(),.done()etc.Edit in response to comments
If you want to invoke a callback within
f1as well as externally you can return the result of the.pipemethod.