Execute a function in JQuery after 2 functions were finished
<p>I have been struggling with this issue all day and couldn't figure out how to make a function that is relay on 2 functions results to execute right after they both finish.</p>

<p>I Tried doing this:</p>

<pre><code>$.when(SetCountryAndLanguage(), GetUserRoles()).done(SetInlineManualTracking());
</code></pre>

<p>But is goes to <code>SetInlineManualTracking()</code> right away without waiting to the 2 functions to finish their jobs.
How can I execute the third function after both functions finish while keeping the async advantages?</p>

<p>This is function number 1:</p>

<pre><code> //Gets the country the user is in and later set the player language.
            function SetCountryAndLanguage() {
                $.get("http://ipinfo.io", function() {}, "jsonp").
                    done(function(response) {
                        inlineCountry = response.country;
                    }).
                    done(SetInlineManualLanguage);
            }
</code></pre>

<p>Function number 2:</p>

<pre><code>//Gets the user roles from the db and update the tracking.
            function GetUserRoles() {
                debugger;
                $.ajax({
                        type: "POST",
                        url: "../Publisher/Service.asmx/SelectUserRoles",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json"
                    }).
                    done(UpdateRoles);
            }
</code></pre>

<p>And the third function that depends on the other 2 previous functions:</p>

<pre><code>function SetInlineManualTracking() {
                debugger;
                //&lt;!-- User tracking data --&gt;
                window.inlineManualTracking = {
                    uid: inlineUid, // Only this field is mandatory
                    email: Cookies.get('email'),
                    username: inlineUserName,
                    name: Cookies.get('name'),
                    created: new Date().getTime() / 1000,
                    updated: new Date().getTime() / 1000,
                    group: inlineCountry,
                    roles: userRoles
                }
            }
</code></pre>