JQuery .ajax() on username validation
<p>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. </p>

<pre><code>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);
                }
            });
        }
    });
}
</code></pre>

<p>/** calling the function to check.  **/</p>

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