validation plugin custom submitHandler ajax
having problem with the custom submitHandler ajax validation ....
here is code
- var validator = $("#signupForm").validate({
submitHandler: function(form) {
$.post(
'ajaxserver/ajax_captcha.php',
{
code: $("#code").val()
},
return_captcha
);
$.post(
'ajaxserver/ajax_username_availability.php',
{
txtEmail: $("#txtEmail").val()
},
return_account
);
if(resp_code1 == 1 && resp_code2 == 1)
{
$("#signupForm")[0].submit();
}
},
- blablabla
variables
"resp_code1" and "resp_code2"
are returns of two callbacks "return_captcha" and "return_account"
but sometimes because of ajax responce delays my IF statement triggered faster than callbacks setting up variables "resp_code1" and "resp_code2" ... so form not submitted even in positive case of ajax checks simply because of ajax delays ....
how to be in this case ? how to prevent this way and force my IF statement wait for two responses of ajax calls and only then check these variables ?
Thanks.