I have used jquery validation to validate email. But the variable whose value is changed in success function is not accessible outside it. It can be done with async=false, but that destroys the purpose of Ajax.
Below is the code:
$.validator.addMethod('verifyemail',function(value,element){
$.ajax({
type: "POST",
url : $.app.urls('base_url')+'account/check_email',
data: {'email' : value},
success: function(msg){
//If email exists, set response to true
if( msg.status == 'false' )
respond = false;
else
respond = true;
}
})
console.log(respond);
return respond;
}, "Email is Already Taken");