2
我有很多reCAPTCHA的谁动态呈现,有时有2个有时50取决于页面。 我已经做了渲染这个:谷歌reCAPTCHA重置函数调用呈现多个验证码
<script src="https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit" async defer></script>
var CaptchaCallback = function(){
$('.g-recaptcha').each(function(index, el) {
grecaptcha.render(el, {'sitekey' : 'myKey'});
});
};
而且放置在此,我要显示验证码:
<div class="g-recaptcha" data-sitekey="myKey"></div>
我有Ajax调用,即提交表单数据process.php,如果表单数据没有通过验证返回的自定义错误
$.ajax({
type : 'POST',
url : 'process.php',
data : $(this).serialize(),
dataType : 'json'
})
.done(function(data) {
if (! data.success) { ...
它按预期工作,但现在我想显示消息的用户作为验证的一部分,如果他忘了要解决验证码。
随着
var response = grecaptcha.getResponse();
if(response.length == 0){
$('.result').append('Captcha incorrect, please click I am not robot');
}
和重置验证码添加此波纹管
if (! data.success) {
grecaptcha.reset();
这是什么做的是:验证码复位如果用户没有完成所有形式的有效。
这一切只适用于第一次出现reCAPTCHA。 我需要它以某种方式告诉它只重置当前正在使用的验证码。
我最好的猜测是与
var form = $(this); //get current form
grecaptcha.reset(form);
尝试它不会工作,因为我需要件ID,并没有形成。 你能帮我吗?