gpt4 book ai didi

php - 我该如何修复此类错误 : "Uncaught ReferenceError: check_email is not defined onblur"

转载 作者:行者123 更新时间:2023-12-01 08:13:14 25 4
gpt4 key购买 nike

<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Amateur</title>
<link rel="stylesheet" href="css/reset.css" type="text/css">
<script src="http://code.jquery.com/jquery-1.8.0.js">
function check_email()
{
var email=$("#txtEmail").val();
$.ajax(
{
type:"POST";
url:"index.php";
data:"email="+email,
success:function(msg)
{
$("#chkEmail").html(msg);
}
});

return false;
}
</script>
</head>

<body>
<form method="post">
<label for="txtEmail">E-mail:</label>
<input id="txtEmail" name="email" type="email" onblur="return check_email()">
<label id="chkEmail" for="txtEmail"></label>
<?php

if(isset($_POST['email']))
{
$user='root';

$pdo=new PDO('mysql:host=localhost;dbname=class;charset=utf8',$user);

$email=$_POST['email'];

$stmt=$pdo->prepare('SELECT email from tbl_users WHERE email=:email LIMIT 1');
$stmt->execute(array(':email'=>$email));

if($stmt->rowCount()>0)
{
echo 'E-mail already use.';
}
else
{
echo 'E-mail not use.';
}

}

?>
</form>
</body>
</html>

我还是 PHP 和 JQuery 的初学者,我想知道如何修复此类错误?我从 Firebug 检查它。流程是,用户输入电子邮件后,它将自动从数据库中检查电子邮件是否存在。并且预期的输出没有显示在我的页面中。

最佳答案

您缺少选择器上的引号,在ajax函数中用分号而不是逗号等分隔参数。

    function check_email() {
var email=$("#txtEmail").val();
$.ajax({
type:"POST",
url:"index.php",
data: {email: email},
success:function(msg) {
$("#chkEmail").html(msg);
}
});
return false;
}

关于php - 我该如何修复此类错误 : "Uncaught ReferenceError: check_email is not defined onblur",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12183009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com