Using AJAX to determine success without captcha capturing

Trying to embed new captcha recaptcha code in my site with an AJAX call. If I use a basic form with a submit button, it works fine, but when I try to execute it through AJAX, it fails.

$.ajax({
    url: "/REST/takeFountainItem",
    dataType: "json",
    type: "POST",
    data: {
        "g-recaptcha-response": $("#g-recaptcha-response").val()
    }
}).done(function(data) {
    console.log(data);
});

Is there a function I need to call or something else? If I look at the header information, it sends a big long key, but no matter what the key cannot verify.

+4
source share
1 answer

Google captcha. , . . : https://developers.google.com/recaptcha/docs/display

:   <script src='https://www.google.com/recaptcha/api.js?onload=reCaptchaCallback&render=explicit'></script>

var RC2KEY = 'sitekey';
function reCaptchaVerify(response) {
    if (response === document.querySelector('.g-recaptcha-response').value) {
        /* do something */
    }
}

function reCaptchaExpired () {
    /* do something when it expires */
}

function reCaptchaCallback () {
    grecaptcha.render('id', {
        'sitekey': RC2KEY,
        'callback': reCaptchaVerify,
        'expired-callback': reCaptchaExpired
    });
}
0

All Articles