我有一个基于AJAX的注册页面,它在客户端和服务器端都进行验证。
当服务器端验证失败时,AJAX会返回错误到屏幕,并尝试使用grecaptcha.reset()重置recaptcha。
重置recaptcha似乎很好地工作了,客户能够重新打勾"I'm not a robot"并继续操作,然而在recaptcha被重置后,页面上的滚动操作导致大量的TypeError: a is null javascript错误在recaptcha_en.js文件中。
当服务器端验证失败时,AJAX会返回错误到屏幕,并尝试使用grecaptcha.reset()重置recaptcha。
重置recaptcha似乎很好地工作了,客户能够重新打勾"I'm not a robot"并继续操作,然而在recaptcha被重置后,页面上的滚动操作导致大量的TypeError: a is null javascript错误在recaptcha_en.js文件中。
TypeError: a is null
https://www.gstatic.com/recaptcha/api2/r20151104115408/recaptcha__en.js
Line 50
代码(简化):
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);
}
}
}
});