谷歌验证码复位不起作用 [英] Google reCaptcha reset doesn't work

查看:511
本文介绍了谷歌验证码复位不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重置谷歌的reCAPTCHA插件,当我通过AJAX提交我的形式,有一定的输入错误或形式被发送。我使用的是同一个页面上的多个部件,所以我使这些小部件明确。

I want to reset Google reCaptcha widget when I submit my form via AJAX and have some input errors or form is sent. I'm using multiple widgets on the same page so I render these widgets explicitly.

我的HTML code:

My HTML code:

<div class="g-recaptcha" id="recaptcha-1"></div>
<div class="g-recaptcha" id="recaptcha-2"></div>
...
<div class="g-recaptcha" id="recaptcha-20"></div>

加载插件

<script src="https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit&hl=en" async defer></script>
<script>
    var reCaptchaCallback = function() {
        var elements = document.getElementsByClassName('g-recaptcha');
        for (var i = 0; i < elements.length; i++) {
            var id = elements[i].getAttribute('id');
            grecaptcha.render(id, {
                'sitekey' : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
            });
        }
    };
</script>

提交表单后:

After submit form:

var id = $('.g-recaptcha', form).attr('id');
grecaptcha.reset(id);

形式提交的表单的实例。

Form is the instance of the submitted form.

一切工作正常时,形式是正确填写。但验证码不会重置或重装。 它试试这个 grecaptcha.reset(),但没有结果。

Everything works fine when form is fill correctly. But reCaptcha doesn't reset or reload. It try this grecaptcha.reset() but no results.

你知道吗?

推荐答案

grecaptcha.reset()方法接受一个可选的 widget_id 参数,默认如果未指定创建的第一个窗口小部件。 A widget_id grecaptcha.render返回()方法创建的每个插件。所以,你需要存储此ID,并使用它来重置特定插件:

The grecaptcha.reset() method accepts an optional widget_id parameter, and defaults to the first widget created if unspecified. A widget_id is returned from the grecaptcha.render() method for each widget created. So you need to store this id, and use it to reset that specific widget:

var widgetId = grecaptcha.render(container);
grecaptcha.reset(widgetId);

见这里

这篇关于谷歌验证码复位不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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