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.

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');
        }
       }
   })

problem in your $.ajax function call in data format it as follows

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