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

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


当前回答

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

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

其他回答

grecaptcha.reset(opt_widget_id)

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

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

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

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

如果您正在使用新的recaptcha 2.0,请使用以下命令: 后面的代码:

ScriptManager.RegisterStartupScript(this, this.GetType(), "CaptchaReload", "$.getScript(\"https://www.google.com/recaptcha/api.js\", function () {});", true);

对于简单的javascript

<script>$.getScript(\"https://www.google.com/recaptcha/api.js\", function () {});</script>

如果您使用的是版本1

Recaptcha.reload();

如果您使用的是版本2

grecaptcha.reset();

对于AngularJS用户:

$window.grecaptcha.reset();