【问题标题】:ReCAPTCHA verification is sending a SyntaxErrorReCAPTCHA 验证正在发送 SyntaxError
【发布时间】:2021-11-04 19:10:13
【问题描述】:

所以今天我试图验证验证码,但不知何故向我发送了一个错误(我确定我做的一切正常)。

这是我为验证它而编写的代码(我在前端这样做只是为了使用 CAPTCHA 进行教育)

try {
        const token = document.querySelector('#g-recaptcha-response').value;
        let url = 'https://www.google.com/recaptcha/api/siteverify?secret=mysecretkey&response=token'
        fetch( url, {
          method: 'POST',
          mode: 'no-cors',
        })
        .then(response => response.json())
        .then(data => console.log(data));
      } catch (err) {
        console.log(err);
      }
    }

我在控制台中打印了 URL,以便我可以手动访问它并检查一切是否正常(没关系)。

这就是我的contact.vue中的内容

<div class="g-recaptcha" data-sitekey="6LfC0kwcAAAAAMZZA0swdErB5_h8y6R_H7hZ85E7" data-size="normal"></div>

错误:Uncaught (in promise) SyntaxError: Unexpected end of input at eval 即使在 trycatch 中,当我单击错误所在的链接时,它指向我执行 result =&gt; result.json() 的行

对此有什么帮助吗?我正在使用 Nuxtjs

【问题讨论】:

    标签: vue.js recaptcha recaptcha-v3 grecaptcha


    【解决方案1】:

    代码末尾有一个额外的}。删除它后,我在 VS Code 上没有收到任何其他语法错误。

    另外,为简洁起见,您可能希望将 let url = 'https://www.google.com/recaptcha/api/siteverify?' 和 url = url + 'secret=mysecretkey&amp;response=' + token; 组合在一起。

    语法错误意味着这是您编写的问题,而不是程序运行方式的问题。

    解决这个问题并重新缩进你的代码,我最终得到:

    try {
        const token = document.querySelector('#g-recaptcha-response').value;
        let url = 'https://www.google.com/recaptcha/api/siteverify?secret=mysecretkey&response=' + token;
        console.log(url);
        fetch( url, {
            method: 'POST',
            mode: 'no-cors',
        })
        .then(response => response.json())
        .then(data => console.log(data));
    } catch (err) {
        console.log(err);
    }
    

    【讨论】:

    • 仍然得到相同的 SyntaxError
    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    相关资源
    最近更新 更多