Possible Duplicate:
jquery ajax return: undefined
I have written the following code to check email already exists or not using jquery and jquery validate.Jquery is used for email format validation. I have called ****check-email.php** file in jquery function.even though there emailaddress is present in my db,the action is get called and it directs to dashboard page.Actually it should not direct to next page because email is already exists.My **"return false;" in jquery function has no effect.It goes to next page even if it is present in db. I am not getting where I am wrong ???
here is my code
index.html:-
<form name="mysignupform" id="mysignupform" class="form-horizontal" action="Dashboard" method="post">
<div class="control-group">
<label class="control-label" for="inputEmail" >Email</label>
<div class="controls">
<input type="text" name="email" id="inputEmail" placeholder="Email" >
</div>
</div>
<br/>
<div class="control-group">
<label class="control-label" for="inputPassword" >Password</label>
<div class="controls">
<input class="password" type="password" name="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="controls">
<input type="hidden" id="body" name="body" value=""></input>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" name="submit" id="signupsubmit"class="btn btn-inverse" onsubmit="return function(e)">Go to Dashboard</button>
</div>
</div>
</form>
my jquery function:-
<script>
$(document).ready(function(){ //newly added
$('#signupsubmit').click(function()
{
alert('in');
var emailVal = $('#inputEmail').val(); // assuming this is a input text field
alert(emailVal);
$.post('check-email.php', {'email' : emailVal}, function(data) {
if(data=='true') return false;
else $('#mysignupform').submit();
});
});
});
</script>
my check-email.php:-
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mojiva", $con);
$sql = "SELECT email FROM user_info WHERE email =".$_POST['email'];
$select = mysql_query($sql,$con);
$row = mysql_num_rows($select);
if ($row > 0)
{
echo 'true';
}
else
{
echo 'false';
}
?>
I tried true false in jquery function immediate after $('#signupsubmit').click(function() this function at this time return true works.but when post is get called it does not have any effect of return false.