我正在通过ajax和php验证用户电子邮件,但这里ajax始终显示电子邮件已退出;
AJAX / Javascript代码:
$.ajax({
type: "POST",
url: "classes/aeAjaxFunction.php",
data: "do=sem&ci=" + ci11,
success: function(msg) {
if(msg ="yes") {
alert('Email already exist');
}
else {
// alert("Occured internal Error. please check network connection");
}
// $('#psid').html("<img src='images/spacer.gif'>");
//$('#email1').html(msg);
//
//$('#sid').sSelect({ddMaxHeight: '300px'});
},
error: function() {
// alert('some error has occured...');
},
start: function() {
// alert('ajax has been started...');
}
});
PHP代码:
<?php
function checkSpEmail($postAr) {
$mysqli = dbconn::get_mysqli();
$email = $postAr['ci'];
$selEmail = "SELECT fld_email FROM tbl_spouse WHERE fld_email = '$email' ";
$res = mysqli_query($mysqli, $selEmail);
$count = mysqli_num_rows($res);
if (mysqli_num_rows($res) == 1) {
echo 'yes';
exit;
}
}
?>
答案 0 :(得分:0)
更改您的ajax代码,您使用的是msg = "yes"
,您必须使用msg == "yes"
$.ajax({
type: "POST",
cache: false,
url: "classes/aeAjaxFunction.php",
data: "do=sem&ci=" + ci11,
success: function(msg) {
if(msg == "yes") {
alert('Email already exist');
}
else {
// alert("Occured internal Error. please check network connection");
}
// $('#psid').html("<img src='images/spacer.gif'>");
//$('#email1').html(msg);
//
//$('#sid').sSelect({ddMaxHeight: '300px'});
},
error: function() {
// alert('some error has occured...');
},
start: function() {
// alert('ajax has been started...');
}
});
答案 1 :(得分:0)
更改
if(msg ="yes")
到
if(msg =="yes")