0

我正在尝试用纯 javascript 和 PHP 实现 Google recaptcha V3,因为我不想使用沉重的 jQuery,而且我对此了解不多。

但是我在实现它时不明白'execute()'方法是什么:

window.addEventListener('DOMContentLoaded', function()
    grecaptcha.execute('XXXXXXXXXXXXXXX', {action: 'homepage'}).then(function(token) {
        document.getElementById('g-recaptcha').value = token;
      });
});

我用 addEventListener() 替换了 '.ready()' 方法,但我找不到 'execute()' 是什么。

我也无法知道“grecaptcha”是什么,这在 Google 的示例中显示。(在示例中,我还没有找到它的声明位置)

我的错误(在 javascript 控制台中)是:

Uncaught ReferenceError: grecaptcha is not defined

我的表格是这样定义的:

<form method="post" action="reaction.php" id="tox" name="frm1">
   ...
   <input type="hidden" id="g-recaptcha" name="g-recaptcha">
   ...
</form>

我的 HTML 标头是这样定义的:

<header>
      <script src="https://www.google.com/recaptcha/api.js?render=xxxxxxxxxxx"></script>
</header>

代码有什么问题,我应该添加什么代码来声明“grecaptcha”?

提前感谢您的回答。

4

0 回答 0