Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  178] [ 7]  / answers: 1 / hits: 18390  / 12 Years ago, mon, october 22, 2012, 12:00:00

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=signupsubmitclass=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.


More From » php

 Answers
5

It's probably because the return false is not referring to the form but the click event.



On the form:



<form name=mysignupform id=mysignupform class=form-horizontal  action=Dashboard method=post onsubmit=email_check($('#inputEmail').val()) >


Then for JQuery:



<script>
$(document).ready(function(){ //newly added

function check_email(emailVal){

{
alert('in');

alert(emailVal);
$.post('check-email.php', {'email' : emailVal}, function(data) {

if(data=='true') return false;
else return true;

});

}
});
</script>

[#82423] Sunday, October 21, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
osvaldo

Total Points: 102
Total Questions: 95
Total Answers: 102

Location: Fiji
Member since Wed, Jul 14, 2021
3 Years ago
;