jQuery Validation - validate email using AJAX call

前端 未结 1 719
遥遥无期
遥遥无期 2021-01-24 17:20

I have an invitation form that should only accept emails handled by GMail. I\'m trying to plug in asynchronous validation, but not sure what should be returned from the server a

相关标签:
1条回答
  • 2021-01-24 18:08

    problem solved.

    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 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');.

    0 讨论(0)
提交回复
热议问题