使用ReCaptcha和jQuery Validate,给出正确的响应,但会出错
我正在使用jQueryvalidation和我的网站的注册表单,底部有一个reCaptcha。 以下是检查表单是否有错误的脚本(仅编辑到相关部分):
$(document).ready(function() { jQuery.validator.addMethod("checkCaptcha", function() { var phpquery = $.ajax({url:"verify.php", type: "POST", async: false, data:{recaptcha_challenge_field:Recaptcha.get_challenge(),recaptcha_response_field:Recaptcha.get_response()}, success:function(resp) { if (resp == 'false') { console.dir(resp); return false; } else { console.dir(resp); return true; } } }); },""); $('#regForm').validate({ rules:{ recaptcha_response_field:{required:true,checkCaptcha:true} }, messages:{ recaptcha_response_field:{checkCaptcha:"Your Captcha response was incorrect. Please try again."} } }); });
当我输入正确的reCaptcha响应并单击提交或制表符出响应文本字段时,它会在控制台中首先显示为true
,然后立即抛出false
并阻止我提交表单。
还会发生的是当输入错误的reCaptcha响应时,它会像它应该的那样抛出false
但是对于我输入的每个字母,它会将其提交给verify.php
并返回false
。 当我最终输入正确的reCaptcha时,它不会识别它并仍然返回false
。
即使输入了正确的响应,重新加载reCaptcha也会引发false
。
我知道verify.php
工作正常,因为当