reCaptcha-验证失败
reCaptcha - fail of validation
我在我的网站上使用reCaptcha,家里一切都很好,但当我在工作中尝试它时,它只加载reCaptcha,但在点击提交按钮时没有经过验证(点击按钮时不要做任何事情)!
我正在使用以下代码进行验证:
function validateRecaptcha() {
alert('inside validation');
var challenge = Recaptcha.get_challenge();
var response = Recaptcha.get_response();
var remoteip = "<%=remoteip%>";
alert('challenge - '+challenge);
alert('response - '+response);
alert('remoteip - '+remoteip);
$.ajax({
type: "POST",
url: "validateRecaptcha.jsp",
async: false,
data: {
remoteip: remoteip,
challenge: challenge,
response: response
},
success: function(resp) {
if($.trim(resp) == "true") {
alert('captcha - right');
document.myform.submit();
}
else {
alert('captcha - wrong');
reloadRecaptcha();
enableWarningRecaptcha('Word Verification:', '.warning', '.WordVerification');
return false;
}
}
});
alert('end of validation');
return false;
}
此外,我使用警报功能进行测试,这些是测试结果:
警报("内部验证");-精细
alert('challenge-'+挑战);-精细
alert('响应-'+响应);-精细
alert('remoteip-'+remoteip);-精细
alert('capcha-right');-失败
alert("捕获错误");-失败
警报("验证结束");-精细
validateRecaptcha.jsp:
<%@ page import="net.tanesha.recaptcha.ReCaptchaImpl,net.tanesha.recaptcha.ReCaptchaResponse" %>
<%
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey("6LcMh-oSAAAAAF8m92XWQ4d2giKMIESghMQDQyQZ");
String remoteip = request.getParameter("remoteip");
String challenge = request.getParameter("challenge");
String res = request.getParameter("response");
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteip, challenge, res);
if (reCaptchaResponse.isValid()) {
out.print("true");
} else {
out.print("false");
}
%>
可能是它的网络问题??还是别的什么?
有人能帮帮我吗!
试试这个:
if($.trim(resp) == "true") {
alert('captcha - right');
document.myform.submit();
} else {
alert('captcha - wrong');
reloadRecaptcha();
enableWarningRecaptcha('Word Verification:','.warning','.WordVerification');
return false;
}
由于您正在提交表单,因此不会看到警报。
要进行调试,请在成功函数中添加警报,以检查它是否会出现。
还添加了ajax中的错误函数:
error: function(ex,a,b,c){
alert("some error");
}
添加此成功函数后调试它是否有任何错误。
注意:您也可以使用firebug来检查ajax的状态密码
去掉那些烦人的Captcha垃圾,因为JavaScript已经提供了一种机制来确定事件是否是用户通过";isTrusted";布尔属性。
用法如下。。。
<button id="logon" onclick="if(event.isTrusted){SomeFunction();}">Logon</button>
任何试图单击此按钮的javascript,如logon.click();将无法通过此测试,函数将不会运行。
相关文章:
- 添加@javascript标记时,Cucumber中的HTTP身份验证失败
- postmates api的AJAX中的HTTP身份验证失败
- Spring Security中的基本身份验证(身份验证失败消息)
- 同一页面上的多个验证码在提交失败时消失
- 表单验证失败,但仍提交
- ExtJs 4 GridPanel with CellEdit:输入的数据在验证失败时丢失
- 验证失败时禁用按钮
- 即使验证失败,表单也会被提交
- jQuery验证另一个值失败
- 即使验证失败,表单也会提交
- jQuery长度验证失败
- 当表单验证失败时,我将如何最好地处理下一个事件
- 验证失败时阻止表单提交(Angular Material)
- OAuth错误:签名验证失败
- 如果在ASP.Net MVC视图中验证失败,请设置httppostedfilebase
- reCaptcha-验证失败
- 循环遍历所有字段,如果任何一个字段的验证失败jquery,则返回false
- 全局变量设置在JavaScript验证中失败
- 验证用户名和密码失败-客户端会话
- jQuery 在多步骤表单上验证失败后中断