感谢阅读我的问题,我有一些问题试图验证recaptcha,使用codeigniter和jquery ajax方法,我总是得到invalid-requste-cookie,这是我的代码的一部分
“欢迎”控制器的一部分
public function anunciese()
{
$data['recaptcha_html'] = $this->recaptcha->recaptcha_get_html();
$data['main_content'] = 'welcome/anunciese';
$this->load->view('includes/'.$this->config->config["tema"].'/template' , $data);
}
public function validar_recaptcha()
{
$this->recaptcha->recaptcha_check_answer(
$_SERVER['REMOTE_ADDR'],
$this->input->post('recaptcha_challenge_field'),
$this->input->post('recaptcha_response_field'));
if ($this->recaptcha->getIsValid() == false)
{
$datos['success'] = false;
$datos['titulo'] = "ERROR";
$datos['mensaje'] = $error = $this->recaptcha->getError();
}
else
{
$datos['success'] = true;
$datos['titulo'] = "";
$datos['mensaje'] = "";
}
echo json_encode($datos);
}
这是视图(它的一部分)
<form class="form-horizontal" method="post">
<fieldset>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input class="form-control" id="inputEmail" placeholder="Email" type="text">
</div>
</div>
<div class="form-group">
<label for="inputNombre" class="col-lg-2 control-label">Nombre</label>
<div class="col-lg-10">
<input class="form-control" id="inputNombre" placeholder="Nombre" type="text">
</div>
</div>
<div class="form-group">
<?php echo $recaptcha_html; ?>
</div>
<div class="form-group">
<input type="button" class="btn btn-primary" value="Suscribirme Gratis" onClick="SalvarProspecto()" />
</div>
最后是我的js代码
function ValidarRecaptcha()
{
var phpencode = true;
var urlx = base_url + 'welcome/validar_recaptcha';
$.ajax({
type: "POST",
url: urlx,
data: {},
async: false,
success: function (data) {
if (phpencode == true) {
data = $.parseJSON(data);
}
console.log(data) //Solo para propositos de debug
if (data.success) {
return true;
} else {
return false;
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Failed " + urlx);
alert(xhr.responseText);
alert(thrownError);
}
});
}
我正在使用此库https://github.com/Cnordbo/RECaptcha-for-Codeigniter
任何帮助将不胜感激
答案 0 :(得分:0)
只是没有ajax请求,并使用表单帮助程序和codeigniter文档使其成为基本表单,就像示例https://github.com/Cnordbo/RECaptcha-for-Codeigniter