I have a jQuery function that uses Ajax. It always returns undefined and I can figure out why.
I notice that if I alert the variable registered in the $.post function it works, but does not if I try it outside.
function signup(){
var username = $('#su-username').val();
var password = $('#su-password').val();
if(username!='' && password!=''){
$.post("register.php", { user: username, pass: password }).done(function(response){
if($.trim(response)=='1'){
alert('Username Taken, Please choose another');
var registered = 0;
}else{
var registered = 1;
}
});
} else {
alert('Username and password cannot be empty');
var registered = 0;
}
return registered;
}