且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery验证 - 使用AJAX调用验证电子邮件

更新时间:2023-11-21 11:04:52

问题解决了。

Javascript代码:

Javascript code:

$('#invite').validate({
    rules: {
        email: {
            required: true,
            email: true,
            remote: {
                url: '/admin/isgmail/',
                type: 'POST',
                dataType: 'json',
                data: {
                    email: function() {
                        return $('#email').val();
                    }
                }
            }
        }
    },
    messages: {
        email: "GMail email is required."
    },
    onkeyup: false
});

invite.php 应返回字符串true如果验证成功,字符串false如果有错误或JSON编码的字符串描述错误: echo json_encode('这是不是Google帐户');

invite.php should return string "true" if validation is successful, string "false" if there was an error OR JSON-encoded string describing the error: echo json_encode('This is not a Google account');.