谷歌reCaptcha获得回应

时间:2016-03-25 10:20:55

标签: response recaptcha

根据谷歌的这个例子(https://developers.google.com/recaptcha/docs/display#example

<script type="text/javascript">
  var verifyCallback = function(response) {
    alert(response);
  };

    grecaptcha.render('example3', {
      'sitekey' : 'your_site_key',
      'callback' : verifyCallback,
      'theme' : 'dark'
    });
  };
</script>


 <form action="?" method="POST">
      <div id="example3"></div>
      <br>
      <input type="submit" value="Submit">
    </form>
    <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer>

我应该收到回复消息并收到警告,但是当我尝试它时,它不会显示任何响应,甚至不会调用方法verifyCallback

我应该在小部件渲染后收到响应,对吗?

1 个答案:

答案 0 :(得分:0)

您的回调名称应与传递给API的回调名称匹配:

<script type="text/javascript">
  var onloadCallback = function(response) {
    alert(response);
  };

    grecaptcha.render('example3', {
      'sitekey' : 'your_site_key',
      'callback' : verifyCallback,
      'theme' : 'dark'
    });
  };
</script>



<form action="?" method="POST">
      <div id="example3"></div>
      <br>
      <input type="submit" value="Submit">
    </form>
    <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
        async defer>