weixin_33725272 2017-04-13 03:05 采纳率: 0%
浏览 40

Recaptcha Ajax无法正常工作

jQuery:

    alert(grecaptcha.getResponse());
    var captchadata = {
        captchavalue: grecaptcha.getResponse()
    }
   $.ajax({
       type:"POST",
       url:"<?php echo base_url()?>index.php/User/captcha",
       data: captchadata,
       success: function(response){
        if(response == 1){
            alert('success');
        }
       }
   })
}

PHP:

    $value = $this->input->post('captchavalue');
    echo $value;
    if(isset($value)){
        $captcha = $this->input->post('captchadata');
        echo 'if executed';
    }
    $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcA1hwUAAAAADGmQKlRcCeugOUkbk-8NSGVhff0&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
    if($response['success'] == true){
        echo 1;
    }
    else{
        echo 0;
    }

Front side it alerting captcha value. My PHP file is not responding even it not displaying $value. How can I resolve this error and why it happening? Please help me.

  • 写回答

2条回答 默认 最新

  • weixin_33724059 2017-04-13 03:32
    关注

    Make sure you are passing the http method the correct way. I can see you are using type instead of method.

    try changing

      $.ajax({
           type:"POST",
           url:"<?php echo base_url()?>index.php/User/captcha",
           data: captchadata,
           success: function(response){
            if(response == 1){
                alert('success');
            }
           }
       })
    

    to

    $.ajax({
           method:"POST",
           url:"<?php echo base_url()?>index.php/User/captcha",
           data: captchadata,
           success: function(response){
            if(response == 1){
                alert('success');
            }
           }
       })
    
    评论

报告相同问题?