Kullanıcı adınızı doğrulama üzerinde JQuery. Ajax ()

0 Cevap php

I was trying to validate username whether exist or not with the following code. But it somehow don't work to prevent the existing username. **NOTE: checkusr2.php is a simple php to check wheter the username in database.

function verifyUser() {
    var usr = $("#username").val();
    $.ajax( {  
        type: "POST",  
        url: "checkusr2.php",  
        data: "username="+ usr,  
        success: function(msg) {
            $("#txtHint").ajaxComplete(function(event, request, settings){
                FormErrors = false;
                if(msg == 'OK') {
                    FormErrors = true;
                    $('#formElem').data('username',FormErrors); 
                } else {
                    $('#formElem').data('username',FormErrors);
                }
            });
        }
    });
}

/ ** Kontrol işlevini çağırma. ** /

verifyUser();
if($('#formElem').data('username')){
    alert('Username exist, please try another username.');
    return false;
}

0 Cevap