jQuery.ajax function doesn't return parameter from it
<p>I need my function to return FALSE if user exists and TRUE if user doesn't exist in database. 
Here is my function code. Firebug showed me that variable flag stays undefined all the time. How can I fix it ?</p>

<pre><code>function checkLogin(login, n) { 
        var flag;

        jQuery.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/checkLogin.ajax",
            data: "login="+login.val(), 

            success: function(response){
                if (response.status == "EMPTY") {
                    alert('Login is free - you can take it');
                    flag = true;
                } 

                if (response.status == "EXISTS") {              
                    alert('Login already exists in Database');
                    login.addClass( "ui-state-error" );
                    updateTips( n );
                    flag = false;
                }

            }
        });

        return flag;
    }
</code></pre>
