繁体   English   中英

与Recaptcha一起使用时,Ajax调用无法正常工作

[英]Ajax call not working properly when used with Recaptcha

我在网站上一起使用PHP和AJAX从JSON URL提取数据并将其显示在网页上。 当我使用它而不实现Recaptcha时,它可以很好地工作,但是当我集成Google的Recaptcha时,仅在每次两次验证码难题都得到解决时才显示结果。 我不确定错误的实际位置,甚至尝试实现自定义验证码,在这种情况下也是如此。 这是带有recaptcha的代码,

验证码和Ajax代码段:

<?php
if ($resp != null && $resp->success):  ?>

echo"hi";

<script>
$(document).ready(function(){

$("#submit").click(function(){

$.post("retrieve_train_between_stations.php", $("#get_train_running").serialize(),  function(response) {  
 $("#success").html(response);


});
return false;


});

});
</script>


<?php
else:
echo "Failed";

?>

完整代码: http : //pastebin.com/UynEiYng

这部分应移至retrieve_train_between_stations.php

require_once "recaptchalib.php";
// your secret key
$secret = "My secret key"; 
// check secret key
$reCaptcha = new ReCaptcha($secret);

$resp = false;

if (isset($_POST["g-recaptcha-response"])) {
    $resp = $reCaptcha->verifyResponse(
        $_SERVER["REMOTE_ADDR"],
        $_POST["g-recaptcha-response"]
    );
}

if ($resp) {
    //display the record
} else {
    echo 'Recaptcha can not be verified.';
}

应该删除if / else并阻止脚本的默认事件

<script>
$(document).ready(function(){

$("#submit").click(function(event){
    event.preventDefault();
    $.post("retrieve_train_between_stations.php", $("#get_train_running").serialize(),  function(response) {  
 $("#success").html(response);


        });
        return false;

    });

});
</script> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM