簡體   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