【问题标题】:How to deal with jquery ajax comments and captcha如何处理 jquery ajax 评论和验证码
【发布时间】:2010-11-18 11:36:02
【问题描述】:

我正在开发社交网络上的评论系统,我正在使用 jquery,我可以毫无问题地使用 ajax 发布 cmets,但有时我需要用户提交验证码表单,如果他们发布了太多 cmets 或其他原因。

我认为最好的方法是将它添加到当前的评论发布部分,如果 php 脚本返回一个响应,说明我们需要做一个验证码表单,那么我想自动打开一个对话框屏幕上的窗口,让用户填写验证码表格,然后继续并在那里发表评论。

这对我来说有点复杂,但我认为我已经完成了大部分工作,也许你可以阅读下面的我的 cmets 并帮助我处理验证码部分,主要是关于如何触发打开对话框,如何通过通过验证码评论值/文本并在成功时再次返回评论,如果用户验证码错误,那么它将重新加载验证码

$.ajax({
    type: "POST",
    url: "processing/ajax/commentprocess.php?user=",
    data: args,
    cache: false,
    success: function (resp) {
        if (resp == 'captcha') {
            //they are mass posting so we need to give them the captcha form
            // maybe we can open it in some kind of dialog like facebox
            // have to figure out how I can pass the comment and user data to the captcha script and then post it
        } else if (resp == 'error') {
            // there was some sort of error so we will just show an error message in a DIV
        } else {
            // success append the comment to the page
        };
    }
});

【问题讨论】:

    标签: jquery ajax captcha


    【解决方案1】:

    我想我会选择使用modal dialog that comes with the jQuery UI library。然后,我会将 AJAX 调用包装在一个函数中,以便递归调用它。我将创建一个处理显示验证码图像的 DIV (#captchaDialog) 和一个用于输入答案的输入 (#captchaInput)。当用户单击模态对话框上的 OK 按钮时,我将使用新的验证码响应修改原始 args 并调用该函数。由于此解决方案只是修改了原始 args 并将其重新传递到相同的 URL,因此我相信此解决方案对您有用。

    一些示例代码,减去模式对话框的 div 和输入:

    var postComment = function(args) {
        $.ajax({
            type: "POST",
            url: "processing/ajax/commentprocess.php?user=",
            data: args,
            cache: false,
            success: function (resp) {
                if (resp == 'captcha') {
                    $("#captchaDialog").dialog({
                        bgiframe: true,
                        height: 140,
                        modal: true,
                        buttons: {
                         ok: function() {
                            args.captchaResponse = $(this).find("#captchaInput").val();
                            postComment(args);
                         }
                        }
                    });
                } else if (resp == 'error') {
                    // there was some sort of error so we will just show an error message in a DIV
                } else {
                    // success append the comment to the page
                };
            }
        });
    };
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      旁观:

      为了获得最佳用户体验,我强烈考虑实施反向验证码:

      http://www.ccs.uottawa.ca/webmaster/reverse-captcha.html

      我知道这并不能解决您的问题,但我至少必须提到这一点。这是一种不需要代表您的用户进行任何输入的垃圾邮件预防方法。

      【讨论】:

      • 您必须在校园内才能查看此页面:(
      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多