Return False not working inside jQuery.ajax

前端 未结 7 2125
再見小時候
再見小時候 2021-02-08 17:38

P.S.: Read \"EDITED on 2019-06-29\":

I have a webform for updating user information, and when he updates his email a verification is performed via

7条回答
  •  自闭症患者
    2021-02-08 18:13

    You should not use .submit() on this situation, use a flag system instead, .submit() should only be used for

    elements.

    var email = jQuery('#email').val();
    var flag = 0;
    jQuery.ajax({
        type : 'GET',
        url : '/ajax/verify-email.php?email=' + email,
        async: false,
        success : function( d ) {
            if( d == '1' ) {
                alert('Another user is using this email');
                jQuery('input[name="email"]').focus();
                flag = 1;
            }
        }
    });
    if(flag == 1) return false;
    

提交回复
热议问题