Jquery - executing custom function calls in order

function, jquery, sequence

Solution

You can return you ajax call as a deferred which gives you access to the `done` function. http://api.jquery.com/category/deferred-object/

Check out Shauna's answer for a deeper explanation of ajax.

function func(param) {
    //some operations
    return $.ajax()
}

main() {
    //first call
    func(param1).done(function(){
       //wait for done and the run the second
       func(param2);
    });

}

Problem

I'm using jQuery 1.9.1. I have a custom function that does some operations an then performing an $.ajax call. I would like to call this function in sequence. I've tried $.when, but it does not solve my problem. ``` function func(param) { //some operations $.ajax() } main() { //first call func(param1); //wait for done and the run the second func(param2); } ```

Original source