-1

我正在使用 ajax、json 和 jquery 编写评论脚本。

除了最难的部分之外,我已经完成了大部分工作,如果用户在 X 时间内发布 X 数量的评论,我的 php 脚本将在下面的 javascript 代码中返回一个“验证码”触发器,告诉它这个用户需要输入一个在我们将那里的评论发布到数据库之前验证码

下面你会看到我有 3 个返回值选项:成功、错误和验证码

当验证码返回时,我想在屏幕上打开一个弹出对话框并加载我的验证码脚本,到目前为止一切正常。

现在我需要提交验证码脚本,不仅是验证码值,还有我的用户评论,所以我只需要用评论值填充一个隐藏的表单字段。很简单,我还没做。现在,如果用户得到错误的验证码值,它需要重新加载屏幕,但再次弹出验证码屏幕,并且评论仍然隐藏在表单值中。这就是棘手的部分出现的地方。

在阅读了我的计划并查看了下面的代码后,您认为我走在正确的轨道上吗?有什么更好的方法建议吗?

<script type="text/javascript">
$.ajax({
    type: "POST",
    url: "process.php",
    data: dataString,
    dataType: "json",
    success: function(data) {
       if (data.response === 'captcha') {
            //they are mass posting so we need to give them the captcha form
            // I can send the users sanitized comment through the captcha script somehow
            // 'data.comment' is holding the comment value
            jQuery.facebox(function() {
                // This opens up a facebox dialog on the screen and popolates it with the captcha image and script
                jQuery.get('captchabox.php', function(data) {
                    jQuery.facebox( '' + data + '')
                    data.comment;
                })
            })
       } else if (data.response === 'success') {
            // success append the sanitized-comment to the page
            $('#comments').prepend(data.comment);
       } else if (data.response === 'error') {
            // just an alert for testing purposes
            alert('sorry there was an error');
       };
    }
});
</script>

更新:

经过更多思考,我似乎也需要让我的验证码也使用 ajax,否则会重新加载页面 =(

4

1 回答 1

-1

我最终这样做了,效果很好。Recaptcha,其他人认为这是如何相关的还不得而知

于 2009-08-25T00:24:38.597 回答