我在我的网站上使用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;
}
此外,我还将警报函数用于测试,这些是测试结果:
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");
}
%>
可能是它的网络问题?还是别的什么?
有人能帮帮我吗?
发布于 2013-11-25 11:01:12
试试这个:
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代码的状态。
发布于 2020-07-22 21:14:13
摆脱那些恼人的Captcha垃圾,因为JavaScript已经提供了一种机制来确定用户是否通过"isTrusted“布尔属性启动了一个事件。
用法如下..。
<button id="logon" onclick="if(event.isTrusted){SomeFunction();}">Logon</button>
任何单击此按钮的javascript尝试(如logon.click();)都会失败,该函数将不会运行。
https://stackoverflow.com/questions/20190394
复制相似问题