Welcome Guest, Not a member yet? Register   Sign In
[jquery]Form validation: async true of false?
#1

(This post was last modified: 09-15-2018, 06:38 AM by ciadmin.)

For some reason form validation does't work when I set up async true, but on the other side if I set up to FALSE then I get in browser console:
Quote:jquery.min.js:4 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.


Code:
function validateForm(form) {
var flag = 0;
var status = false;
var captcha = $('#captcha1').val();
if (captcha == '') {
flag = 1;
var error_text = 'Please enter Image Text.';
$('#capacha_error').html(error_text);
$('#capacha_error').show();
}
if (flag == 1)
{
return status;
} else
{
$.ajax({
type: "POST",
url: "<?= base_url() ?>captcha/checkcaptcha",
global: false,
data: {captcha: captcha},
dataType: 'JSON',
async: true,   ---- DOES'T WORK WITH 'TRUE' OPTION
success: function (data) {
if (data.error)
{
var error_text = 'Captcha Code does not Match Please check.';
$('#capacha_error').html(error_text);
$('#capacha_error').show();
status = false;
} else if (data.success)
{
status = true;
}
}
});
return status;
}
}

Why doesn't it work whith asynchronous request?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB