gpt4 book ai didi

jQuery Validate 远程电子邮件验证不起作用

转载 作者:行者123 更新时间:2023-12-01 06:07:33 25 4
gpt4 key购买 nike

在我的用户编辑器页面中,我试图检查输入的电子邮件是否被其他客户使用,但不是客户当前的电子邮件。这是我的代码,它似乎没有显示错误消息,但我的表单无法提交。

这是我的 JS:

$("#cedit").validate({
rules : {
email : {
email : true,
remote : {
url : "ajax_checkemail.php",
type : "GET",
data : {
email : function() {
return $("#email").val();
},
custid : function() {
return $("#editc").val();
}
}
}
}
},
messages : {
email : {
remote : "Email is in use"
}
}
});

还有 PHP

include 'common.php';
$valid = false;
if(isset($_GET['email']))
{
$email = $_GET['email'];
$query = "SELECT * FROM `customer` WHERE `email_address` = '$email'";
if(isset($_GET['custid']) && !empty($_GET['custid']))
{
$custid = $_GET['custid'];
$query .= " AND `customer_id` != '$custid'";
}
$result = query($query);
$count = mysql_num_rows($result);

if ($count == 0)
{
$valid = true;
}
}
echo json_encode($valid);

当我直接访问 PHP 并将 GET 参数放入 URL 中时,PHP 工作正常,但由于某种原因,它无法正确验证,因此不会让表单提交。

最佳答案

我从来没有使用过这个远程验证,但是你不需要在你的php脚本中将响应类型设置为json吗? 如 header('Content-type: application/json');

关于jQuery Validate 远程电子邮件验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4111931/

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