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.
But problem is program not responding in while loop and not posting ajax call.
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;
You really shouldn’t do that. Active waiting is likely to block the whole browser or at least the current tab.
Put all code that needs to run after the request succeeded in the success callback.
Since you apparently want to both submit the form normally and use AJAX (why?!), the solution is rather simple: prevent the original submit from being handled by the browser by calling
e.preventDefault()(ebeing the first argument passed to the jQuery event handler) and after the AJAX request succeeded.submit()the form. To avoid the AJAX request from being sent again you might need to unbind the submit event handler or set a variable after the AJAX request completed.