[英]Ajax request with codeigniter forbidden
I'm trying to do an ajax request with jquery and codeigniter framework, but when I try to access to the server page, I have a forbidden access.我正在尝试使用 jquery 和 codeigniter 框架执行 ajax 请求,但是当我尝试访问服务器页面时,我的访问被禁止。
Here's my jquery code :这是我的 jquery 代码:
$('#btHello').click(function () {
var name = $('#name').val();
alert(name);
$.ajax({
type:'POST',
data:'name='+ name,
url:'<?php echo base_url();?>index.php/AjaxTest/ajaxtest',
success: function(result, status){
$('#result1').html(result);
},
error: function (result, status, error) {
alert(error);
}
});
});
The error alert just shows "Forbidden", nothing more.错误警报仅显示“禁止”,仅此而已。
Does anyone know what is the problem ?有谁知道是什么问题?
Here's the controler :这是控制器:
class AjaxTest extends CI_Controller {
public function index() {
$this->load->view('home/head');
$this->load->view('home/nav');
$this->load->view('test/ajaxTest');
$this->load->view('home/foot');
}
public function ajaxTest(){
$name = $this->input->post('name');
echo 'Hello '.$name;
}
}
Send发送
$this->security->get_csrf_token_name() : $this->security->get_csrf_hash()
with the request.随着请求。 hope it'll solve your problem
希望它能解决你的问题
$.ajax({
url: "<?php echo site_url().'/admin/getNewLocations' ?>",
type: "POST",
data: {
func: 'getNewLocations',
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
},
success: function(data) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.