remote: "/some/remote/path"
该路径将通过 $_GET 中的字段值传递。所以..在您的情况下实际调用的是:
/some/remote/path?email=someemailuriencoded
让服务器端代码只返回文本 true 或 false。
然后相应的消息也命名为remote。
remote: "The corresponding email already exists"
我的代码类似:
$("#password_reset").validate({
rules: {
email: { required: true, email: true, minlength: 6, remote: "/ajax/password/check_email" }
},
messages: {
email: { required: "Please enter a valid email address", minlength: "Please enter a valid email address", email: "Please enter a valid email address", remote: "This email is not registered" }
},
onkeyup: false,
onblur: true
});
php中对应的服务器端代码:
$email_exists = $db->prows('SELECT user_id FROM users WHERE email = ? LIMIT 1', 's' , $_GET['email'] );
if ( $email_exists ) { echo 'true'; } else { echo 'false'; }
exit;
当然,这是使用我的数据库抽象的东西,但你明白了。