V
V
vasyok282018-03-04 14:14:08
reCAPTCHA
vasyok28, 2018-03-04 14:14:08

Invisible reCAPTCHA why only works once?

The essence of the problem is that I form reCAPTCHA using ajax in the dialog box, and it works only once, if you close the dialog box and open it again, then the handler will not be called data-callback=" onSubmit "
And now how everything works:
1. In the header

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

2. When receiving an ajax request, I set the contents of the modal window for captcha 3. When forming the modal window, I call the function
<div id="g-recaptcha"></div>
var captcha = null;

function createRecaptcha() {
    if(captcha === null) {
        captcha = grecaptcha.render("g-recaptcha", {
            sitekey: "6Ld-xToUAAAAAAda6yqAaKyI3VLa_hFIBE9KBtxB",
            callback: "onSubmit",
            size: "invisible"});
    } else {
        grecaptcha.reset(captcha);
    }
}

5. When the submit button is clicked, I intercept the click and call the function
grecaptcha.execute(captcha);
4. OnSubmit (token) must be called for further work.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question