2017-04-13 66 views
0

的jQuery:的Recaptcha AJAX不wotking

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

正面它提醒captcha值。即使不显示$value,我的PHP文件也没有响应。我该如何解决这个错误以及它为什么发生?请帮帮我。

回答

0

问题是如下

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

请确保您正确传递http方法。我可以看到你使用的是类型而不是方法。

尝试data格式在$.ajax函数调用改变

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

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