使用验证码使用Ajax .... JavaScript的加载问题 [英] using reCAPTCHA with ajax....javascript loading problem

查看:147
本文介绍了使用验证码使用Ajax .... JavaScript的加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的一种形式来实现的reCAPTCHA,......但我用ajax的提交。 (更具体的原型的Ajax.Updater)

I trying to implement reCAPTCHA in one of my forms,...but i am using ajax as the submission. (More specifically the prototype ajax.updater)

在我提交和错误检查我的状态我尝试加载reCAPCHTA部件啄(在我的更新div元素),它基本上只是调用JavaScript文件,如下所示:

Once I submit and error check my form I try to load the reCAPCHTA widget thingy (in my updated div element) which basically just calls a javascript file like so:

<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6Le6SwUAAAAAAIWm8wCRFd8SrI-H0R1Yx4Tkw2Ks"></script>

不过JS文件没有被读取...我已经试过evalScripts的所有组合:真实,evalJS:力等在Ajax.Updater的.....但是我不认为我为什么JS文件不处理的一个很好的理解:(

However the JS file is not being read?...and i've tried all combination of evalScripts:true and evalJS:'force' etc. in the ajax.updater.....however i don't think I have a very good understanding of why the js file isn't processing :(

如果任何人都可以揭示出这个问题的一些光明,我会非常AP preciative。

If anyone can shed some light on this issue I will be very appreciative.

谢谢,安德鲁

推荐答案

这并不解决您的具体问题,但<一href="http://www.darksideofthecarton.com/2008/12/15/validating-recaptcha-with-jquery-and-ajax/comment-page-1/"相对=nofollow>纸箱'的黑暗面有一些优秀的$ C $下通过jQuery AJAX验证验证码这可能会有帮助。

This doesn't address your exact problem, but 'Dark Side of the Carton' has some excellent code for validating reCAPTCHA via jQuery AJAX which might help.

在总结:

添加以下JavaScript:

Add the following Javascript:

$(function() {
    function validateCaptcha() {
        var challengeField = $('input#recaptcha_challenge_field').val(),
            responseField  = $('input#recaptcha_response_field').val();

        // alert(challengeField);
        // alert(responseField);
        // return false;

        var html = $.ajax({
            type: 'POST',
            url: 'ajax.recaptcha.php',
            data: "recaptcha_challenge_field=" + challengeField + "&amp;recaptcha_response_field=" + responseField,
            async: false
        }).responseText;

        if (html.replace(/^\s+|\s+$/, '') == "success") {
            $('#captchaStatus').html(' ');
            // Uncomment the following line in your application
            return true;
        } else {
            $('#captchaStatus').html(
                'Your captcha is incorrect. Please try again'
            );
            Recaptcha.reload();
            return false;
        }
    }

    // Modified as per comments in site to handle event unobtrusively
    $('#signup').submit(function() {
        return validateCaptcha();
    });
});

如果失败,如果验证码匹配只输出单词成功和消息,并从reCaptchta响应这一点很重要,因为我们正在寻找这个词成功:

然后添加其中ajax.recaptcha.php文件。我们的validateCaptcha()函数。

Then add the ajax.recaptcha.php file which: "outputs only the word "success" if the captcha matches and a message and the response from reCaptchta if it fails. This is important because we are looking for the word success in our validateCaptcha() function."

require_once('/inc/recaptchalib.php');
$publickey  = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // you got this from the signup page
$privatekey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX';

$resp = recaptcha_check_answer(
    $privatekey,
    $_SERVER['REMOTE_ADDR'],
    $_POST['recaptcha_challenge_field'],
    $_POST['recaptcha_response_field']
);

if ($resp->is_valid) {
    ?>success< ?
} else {
    die(
        "The reCAPTCHA wasn't entered correctly. Go back and try it again." .
        "(reCAPTCHA said: " . $resp->error . ")"
    );
}

的例子是在PHP,但我适应它很容易与的Zope / Python的

The example is in PHP, but I adapted it easily to work with Zope/Python

这篇关于使用验证码使用Ajax .... JavaScript的加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆