我制作了一些 jQuery Ajax 代码来检查数据库中是否已经存在电子邮件,我无法让它正常工作 我的 Html 代码:
<form name="emailForm" id="emailForm" method="post" action="signin.php">
<input type="email" name="email" id="email" required="required" />
<input type="submit" value="Get Started Now!" />
</form>
jQuery代码:
$(function(){
$("#emailForm").submit(function(){
$.ajax({
type:POST,
url:"signin.php",
data: "email="+$("#email").val(),//{email:$("#email").val()},
success: function(msg){
if(msg == '1'){
alert("Already exists.");
}else{
alert("C'est cool, Hak la suite");
}
}
});
return false;
});
});
signin.php 代码
function check_email($email){
include 'bdd.php';
$query = "SELECT * FROM users WHERE email = '$email'";
$resultat = mysqli_query($link,$query);
$msg = mysqli_num_rows($resultat);
return $msg;
}
if(isset($_POST['email'])){
if(check_email($_POST['email']) == 1){
$msg = "1";
}else{
$msg = "0";
}
}
echo $msg;
它转到 signin.php 并打印 1 或 0,任何想法如何使 Ajax 工作?