I have an AJAX based registration page which validates on both the client and the server.
When the server side validation fails the AJAX returns the errors to the screen and attempts to reset the recaptcha using grecaptcha.reset().
Resetting the recaptcha appears to work fine and the customer is able to retick the "I'm not a robot" box and carry on, however after the recaptcha has been reset and scroll action on the page causes a massive number of TypeError: a is null javascript errors in recaptcha_en.js.
TypeError: a is null
https://www.gstatic.com/recaptcha/api2/r20151104115408/recaptcha__en.js
Line 50
Code (simplified):
var recaptcha1;
var onRecaptchaLoad = function () {
recaptcha1 = grecaptcha.render('gRecaptcha', {
'sitekey': 'my site key',
'callback': CaptchaResponse
});
};
$.ajax({
type: "POST",
url: "SaveDetails",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: data,
cache: false,
success: function (result) {
if (result != null) {
if (result.d.Success) {
//success
}else{
grecaptcha.reset(recaptcha1);
}
}
}
});
For reCaptcha v2, use: grecaptcha. reset();
One solution is to change the way you are submitting your form. Move the reCaptcha submission to a secondary server side page if possible. This will create a fresh condition where the interaction with Google is immediate.
Have a same problem and everything I found useful to think about is that recapthca is trying to load old version or something (I can not reproduce but I got another version of captcha under certain circumstances)... and another thought related to modal window where my recaptcha show same behavior.
BTW: not only scroll event trigger errors spamming but any window re-sizing as well.
I hope any of this can help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With