P
P
ProF1NE2020-04-24 20:08:13
PHP
ProF1NE, 2020-04-24 20:08:13

AJAX problem, why doesn't validation work?

Shalom everyone, my head already hurts, I can’t understand what’s wrong, why it doesn’t work
The whole point ... enter the code, if it’s correct, we get a message, if not, then repeat (it seems everything is simple), but I have an inpat check in the code on jquery:

$('input#InputUpVerCode').keyup(function(){

        var id = $(this).attr('id');
        var val = $(this).val();

        switch(id) {
            case 'InputUpVerCode':
                if(val != '' && val.length == 6){
                  		$(this).parent().removeClass('error').addClass('not_error');

                  		$('#vercode').removeClass('signup').addClass('signin').removeAttr('disabled');
                  
               		}else{
                  		$(this).parent().removeClass('not_error').addClass('error');
                  		$('#vercode').removeClass('signin').addClass('signup').prop('disabled', true);	
               		}
            break;
        } 
    });

this code works fine for the first time, and after entering the code incorrectly, it stops working, the style does not change, the button is not active
The whole code:
$mail = $_POST['mail'];
$code = $_POST['vercode'];

$db->query("SELECT * FROM users WHERE email = '$mail'");
$user = $db->FetchArray();

$code2 = $user['vercode'];

if($code == $code2) {
echo "Успеншо!";
} else {
?>

<span class="error">Не верный код!</span>
<p>На почту <?=$mail; ?> было отправлено сообщение с кодом подтверждения:</p>
  <div class="input">
    <span>Ваш Код:</span>
    <input type="text" id="InputUpVerCode">
  </div>
  <a href="">Отправить еще раз</a>
  <button class="signup" id="vercode" disabled type="button">Подтвердить</button>
  <span class="signin" style="text-align: center; cursor: pointer; display: block;" type="button" onclick="goSignIn();">Войти</span>

<script>	
  $(document).ready(function(){
    $('input#InputUpVerCode').keyup(function(){

        var id = $(this).attr('id');
        var val = $(this).val();

        switch(id) {
            case 'InputUpVerCode':
                if(val != '' && val.length == 6){
                  		$(this).parent().removeClass('error').addClass('not_error');

                  		$('#vercode').removeClass('signup').addClass('signin').removeAttr('disabled');
                  
               		}else{
                  		$(this).parent().removeClass('not_error').addClass('error');
                  		$('#vercode').removeClass('signin').addClass('signup').prop('disabled', true);	
               		}
            break;
        } 
    });
    $('#vercode').click(function(e){
      var mail = "<?=$mail; ?>";
          e.preventDefault();
          if($('.not_error').length == 1){
           	$.ajax({
                  url: '/ajax/signup.vercode.php',
                  type: 'post',
                  data: {"vercode": $('#InputUpVerCode').val(), "mail": mail},
                  dataType: "html",
                 	success: function(html){
                      $('.modal-body').html(html);
                	}
          	});
          }else{
            	return false;
         	}
     	});
</script>

<?php

}

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
ProF1NE, 2020-04-25
@ProF1NE

The error was banal... at the end I didn't close the document.ready() function, the
topic is closed)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question