0

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(){
        $('#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

Antonio Laguna
  • 8,973
  • 7
  • 36
  • 72
  • What are you returning from the check-user.php script? You should be able to see what comes back in the Net tab of Firebug. – matt May 24 '11 at 19:01
  • 0 or 1. I've checked because I also call to this file to check if the user exists on field update and worked. – Antonio Laguna May 24 '11 at 20:00
  • Is it only in Firefox that you get an error? Probably you have already read this? http://stackoverflow.com/questions/5433415/error-attempt-to-run-compile-and-go-script-on-a-cleared-scope – matt May 24 '11 at 22:17
  • Yes I did! And, as I state in the post, I've tried with other browsers with no results :( – Antonio Laguna May 26 '11 at 15:41
  • Asking once again: what are you returning from the check-user.php script? – Nowaker Aug 17 '11 at 15:49

1 Answers1

0

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;
    }
}
Pyronhell
  • 66
  • 6