Possible Duplicate:
How to return the response from an AJAX call from a function?
i am creating a registration page with email id and password . i have called onsubmit event in registration page which call's checkData() function which is written in a common.js file. i have a ajax function to check whether email id exist in database or not ? but my problem is when i keep alert message after the completion of checking my ajax function works fine but if alert is removed it enter's data in to database. here is the code of ajax
else
{
$(function() {
$.ajax({
url : 'RegCheck.php',
type : 'POST',
data : 'User=' + address,
success : function(result){
if(result != "No")
{
document.getElementById("EmailChk").innerHTML = result;
Valid = false;
}
}
});
});
document.getElementById("MailMand").innerHTML = "" ;
}
alert(Valid);
return Valid;