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;
}
正面警告captcha
值。我的PHP文件没有响应,即使它没有显示$value
。如何解决此错误及其发生的原因?请帮帮我。
答案 0 :(得分:0)
确保以正确的方式传递http方法。我可以看到你使用的是类型而不是方法。
尝试更改
$.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');
}
}
})
答案 1 :(得分:0)
$.ajax
data
函数调用中的问题格式如下
$.ajax({
type:"POST",
url:"<?php echo base_url()?>index.php/User/captcha",
data: {captchadata:captchadata},
success: function(response){
if(response == 1){
alert('success');
}
}
})