【问题标题】:Detect error for google recaptcha execute检测谷歌recaptcha执行的错误
【发布时间】:2021-05-22 06:50:45
【问题描述】:

如果发生错误、没有连接或超时连接,我如何为 grecaptcha.execute() 设置一个等效的 .fail。

<script>
  function onClick(e) {
    e.preventDefault();
    
    grecaptcha.ready(function() {
        grecaptcha.execute('reCAPTCHA_site_key', {action: 'submit'}).then(function(token) {
            // Code if no error
        });

        // Catch the error if occurred
    });
  }

【问题讨论】:

    标签: javascript grecaptcha


    【解决方案1】:

    您是否尝试将其传递到 try/catch 块中?

    function onClick(e) {
      e.preventDefault();
    
      try {
        grecaptcha.ready(function () {
          grecaptcha
            .execute("reCAPTCHA_site_key", { action: "submit" })
            .then(function (token) {
              // Code if no error
            });
        });
      } catch (e) {
        console.log(e);
      }
      // Catch the error if occurred
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2022-06-16
    • 2020-09-17
    • 2019-01-18
    • 1970-01-01
    相关资源
    最近更新 更多