开发者

attempt to run compile-and-go script on a cleared scope

I have a simple form validation with ajax and jquery. I've done this before but now it seems to be failing over and over.

The title is the error I see in the firebug console. After some google research, seems to be a problem with managing windows but... I'm not trying to do that and I also tried in other browsers with identical results. The form submits...

This is the function:

$("#login-da").submit(function(){
    开发者_如何学C    $('#error').hide();
        var username = $('#username').val();
        var password = $('#password').val(); 
        var query = 'username=' + username + '&pass=' + password;
        $.ajax({
            type: "POST",
            url: "functions/check-user.php",
            async: false,
            data: query,
            cache: false,
            success: function(response){
                        if(response == 0) {                         
                            $('#error').slideDown();
                            var error = 1;
                        }
                        else {
                            var error = 0;
                        }
                    }
        });
        if (error == 1){        
            return false;
        }
    });

I've tried to return false directly in the success function with identical results. The error begins to show but the form submits anyways and nothing appear. I've also noticed through debugging that anything outside the ajax call isn't executed.

Any help would be really appreciated


Try using Number() on the response data, also, check the scope of the error variable on the response funcion:

success: function (response) {
    var result = Number(response);
    if (result == 0) {
        $('#error').slideDown();
        error = 1;
    } else {
        error = 0;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜