I'm trying to access a global variable inside of the success
function of a $.ajax()
call. Basically I have something like this:
function someFunc(email) {
var ret;
$.ajax({
url: '/checkuseremail.php?email='+email,
cache: false,
success: function(data) {
if ( data != '1' ) {
alert(email+'\n'+data);
ret = false;
} else {
alert(email+'\n'+data);
ret = true;
}
}
});
alert(ret); // outputs "undefined"
return ret;
}
I'm aware that the alert()
at the bottom is being called before the ajax response has been given, but I'm not sure what else to do. I would just put the return statement inside of the success
function, but that would only return that function, not the parent one.
Any ideas how to do this?