Double ajax request response
<p>I'm using ajax successives requests and I need do a callback when all the successives requests are done</p>

<pre><code>function doAjaxRequest(data, id) {
    // Get payment Token
    return $.ajax({
        type: "POST",
        url: 'exemple1.php',
        data: data
        success: function(msg){
            $.ajax({
                type: "POST",
                url: 'exemple2.php',
                data: msg,
                success: function(msgr) {
                    document.getElementById(id).value=msgr;
                },
                error:function (xhr, status, error) {
                    //Do something
                }
            });
        },
        error:function (xhr, status, error) {
            //Do something
        }
    });
}

$.when(
    doAjaxRequest(data, "input-1"),
    doAjaxRequest(otherData, "input-2")
).done(function(a1, a2){
    //Need do something when both second ajax requests (example2.php) are finished
}
</code></pre>

<p>With this code, the done function is call before my calls to "exemple2.php" are succeeded.</p>

<p>How can I wait for that?</p>

<p>Thanks for answering!</p>