I wrote a check for correctness and busyness of the E-mail address of users, but for some reason the POST request is not correct. The request takes more than a second and for some reason you cannot use the response from the request in the condition
<script> if(email == '') { event.preventDefault(); $("#email").addClass('input_error'); $('#error_reg').show(); $('#error_reg_info').text('Необходимо заполнить все поля'); } else { var resEmail = email.search(/[-0-9a-z_]+@[-0-9a-z_]+\.[az]{2,6}/i); if(resEmail == -1){ event.preventDefault(); $("#email").addClass('input_error'); $('#error_reg').show(); $('#error_reg_info').text('Неверный формат Email'); } else { var url = host+"/resources/classes/testEmail.class.php"; $.post(url, { email: email}, function(data){ //Если здесь вывести ответ, то он работает ( alert(data); ) if(data == 'no') { event.preventDefault(); $("#email").addClass('input_error'); $('#error_reg').show(); $('#error_reg_info').text('E-mail занят'); } else { $("#email").removeClass('input_error'); } }); } } </script> <?php include '../basic/config.php'; include '../basic/function.php'; $email = tm($_POST['email']); $query = "SELECT `id` FROM `users` WHERE `email`='{$email}' LIMIT 1"; $sqle = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($sqle)==1) { echo "no"; } else { echo "yes"; } ?>