我有一个使用AJAX的注册表单,以便我想在任何时候发生错误(即用户名已经在使用)刷新Recaptcha图像。

我正在寻找与ReCaptcha兼容的代码,使用JavaScript重新加载它。


当前回答

grecaptcha.reset(opt_widget_id)

重置reCAPTCHA小部件。可以传递一个可选的小部件id,否则函数将重置创建的第一个小部件。(来自谷歌的网页)

其他回答

试试这个

<script type="text/javascript" src="//www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script>
<script type="text/javascript">
          function showRecaptcha() {
            Recaptcha.create("YOURPUBLICKEY", 'captchadiv', {
              theme: 'red',
              callback: Recaptcha.focus_response_field
            });
          }
 </script>

<div id="captchadiv"></div>

如果调用showRecaptcha,验证码将被一个新的验证码实例填充。

或者,您可以模拟单击刷新按钮

// If recaptcha object exists, refresh it
    if (typeof Recaptcha != "undefined") {
      jQuery('#recaptcha_reload').click();
    }

重要提示:不再支持reCAPTCHA API的1.0版本。请升级到2.0版本。

你可以使用grecapcha .reset();重置验证码。

来源:https://developers.google.com/recaptcha/docs/display js_api

对于AngularJS用户:

$window.grecaptcha.reset();
grecaptcha.reset(opt_widget_id)

重置reCAPTCHA小部件。可以传递一个可选的小部件id,否则函数将重置创建的第一个小部件。(来自谷歌的网页)