[英]Form not submitting with recaptcha validated using Jquery ajax
I want to submit my form when recaptcha is validated and not submit the form when it is not validated. 我想在Recaptcha验证时提交表单,而在未验证时不提交表单。 My form is not submitting when ajax return a string "true".
当ajax返回字符串“ true”时,我的表单未提交。 How do i do this?
我该怎么做呢?
$("#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;
});
I have resolved it. 我已经解决了。 The solution is that i need to set async to false.
解决方案是我需要将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");
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.