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');
            }
           }
       })
    
    评论
  • MAO-EYE 2017-04-13 05:11
    关注

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

报告相同问题?

悬赏问题

  • ¥15 如何在EXCEL某单元格中查找是否存在另一列中的内容。
  • ¥50 非对称加密(相关搜索:密码学)
  • ¥15 关于非编程寻迹小车的分析
  • ¥15 java导出EXCEL这里已经执行成功了,但是流浪器没有下载
  • ¥15 帮我把代码改的能正常运行就行
  • ¥50 有限元修正、模型修正、最小二乘法,详细步骤
  • ¥15 用plc编写梯形程序
  • ¥15 关于#物联网#的问题:新大陆AIOT中,按照手册教程进行添加,设置完成后网关一直不上线,显示Never这是网络服务的信息
  • ¥15 这个要用一维热方程但是我不知道怎么运用这个公式
  • ¥15 OpenFOAM多孔介质传热模型建模