我想在验证recaptcha时提交我的表单,并且在未经验证时不提交表单。当ajax返回一个字符串" true"时,我的表单没有提交。我该怎么做?
$("#submitbtn").click(function(e){
challengeField = $("input#recaptcha_challenge_field").val();
responseField = $("input#recaptcha_response_field").val();
$.ajax({
type: "POST",
url: "/ballot/validatecaptcha",
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
success: function(data){
if(data == "true"){
$("#form2").submit();
}else{
$("#recaptcha_error").text("Error");
}
}
});
return false;
});
答案 0 :(得分:-1)
我已经解决了。解决方案是我需要将async设置为false。
$.ajax({
type: "POST",
url: "/ballot/validatecaptcha",
async: false,
data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
success: function(data){
if(data == "true"){
$("#form2").submit();
}else{
$("#recaptcha_error").text("Error");
}
}
});