表单未使用Jquery ajax验证的recaptcha提交

时间:2014-09-12 04:12:08

标签: javascript jquery recaptcha

我想在验证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;
});

1 个答案:

答案 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");
        }
    }
});