[Vuejs]-ReCAPTCHA verification is sending a SyntaxError

0👍

You’ve got an extra } at the end of the code. After removing that, I’m not getting any other syntax errors on VS Code.

Plus, you may want to combine let url = 'https://www.google.com/recaptcha/api/siteverify?' and url = url + 'secret=mysecretkey&response=' + token; for brevity’s sake.

Syntax errors mean it’s a problem with what you wrote, not with how the program runs.

Fixing this and re-indenting your code, I end up with:

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);
}

Leave a comment