Delay till ajax response like thread.sleep()
<p>I have button which post values of form to url but during post i want to capture that value into my database too.
So on button click i made new thread of ajax and paused  by while loop so user can not redirect due to post of form. </p>

<p><strong>But problem is program not responding in while loop and not posting ajax call.</strong> </p>

<pre><code>function btnSubmitId_Onclick() {

    window.setTimeout(function () {

        var FirstName = $(txtFirstNameId).val()
        var Email = $(txtEmailId).val()

        AJAXPost(   //Url
                "Signup"
                , //Data
                {Ip: Ip, CustomerKey: CustomerKey, FirstName: FirstName, Email: Email }
                , //Success
                function (data) {
                    response2 = true;
                }
                , //error
                function (xhr, textStatus, errorThrown) { }
            );

    }, 0);


    var date = new Date();
    var curDate = null;
    do { curDate = new Date(); }
    while (response2 == false)

}

var response2 = false;
</code></pre>
