javascript 未捕获的 ReferenceError:未定义 Recaptcha

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22540612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:19:44  来源:igfitidea点击:

Uncaught ReferenceError: Recaptcha is not defined

javascriptjqueryhtmlajaxrecaptcha

提问by eat-sleep-code

I am running into an issue with implementing the reCaptcha control on a contact form.

我在联系表单上实施 reCaptcha 控件时遇到了问题。

The following error is thrown on load: Uncaught ReferenceError: Recaptcha is not defined

加载时抛出以下错误:Uncaught ReferenceError: Recaptcha is not defined

Here is a partial snippet of the code I am using:

这是我正在使用的代码的部分片段:

<form role="form" id="ContactMessageForm">
    <div class="form-group">
        <div id="CaptchaContainer"></div>
    </div>
    <button type="button" class="btn btn-default" id="ContactMessageSendButton">Send</button>
</form>

<script type="text/javascript" src="/scripts/mail.min.js" defer="defer"></script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
    $(document).ready(function () { 
        /* Initialize reCaptcha Control */
        Recaptcha.destroy();
        Recaptcha.create('6Lc4V_ASAAAAAMnnwUcaTewH1mlOdylMgAyxb_m6', 'CaptchaContainer', {
            theme: 'clean',
            callback: Recaptcha.focus_response_field
        });
    });
</script>

There is most likely a typo in my code, but I am just not seeing it.

我的代码中很可能有错别字,但我只是没有看到。

You can see the actual error get fired at: http://eat-sleep-code.com/#!/contact

你可以看到实际的错误被触发:http: //eat-sleep-code.com/#!/contact

回答by dariush

I have had the same problem and i fixed it with following

我遇到了同样的问题,我通过以下方式修复了它

<script type="text/javascript">
    $.getScript( "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js", function() {
        Recaptcha.create("<PUBLIC_KEY>", "recaptchadiv", {theme: "clean"});
    });
</script>

回答by eat-sleep-code

Using the feedback from @progysm I moved the call to recaptcha_ajax.js so that it was loaded before the renderContent() function was called. This allowed the Captcha image to be displayed.

使用来自@progysm 的反馈,我将调用移到了 recaptcha_ajax.js,以便在调用 renderContent() 函数之前加载它。这允许显示验证码图像。

Unfortunately, I ended up having to abandon the reCaptcha control for this application as the validation methods were blocked due to cross site scripting methods.

不幸的是,我最终不得不放弃此应用程序的 reCaptcha 控件,因为验证方法因跨站点脚本方法而被阻止。

回答by A J

Please confirm if you have given in the right public key and not the private key as following

请确认您是否提供了正确的公钥而不是私钥,如下所示

Recaptcha.create('<public_key>', 'CaptchaContainer', {
        theme: 'clean',
        callback: Recaptcha.focus_response_field
});