Codeigniter 3中禁止发布url 403 [英] POST url 403 forbidden in Codeigniter 3
问题描述
您好,专家您能给我一个建议吗,为什么我要在当前运行在本地主机上的代码点火器上禁用此403.
Hi experts can you give me a suggestion, why I am getting this 403 forbidden on my code igniter currently running on my localhost.
过程如下:
-
我正在使用ajax轻松,平稳地访问和检索模型,控制器到视图中的数据.下图是我到控制器视图中的代码.
I am using ajax for easy and smoothly access and retrieving of data from model, controller to the view the image below is my code in my views to controller.
<div class="modal-header s-example-modal-sm" aria-labelledby="mySmallModalLabel">
× 新问题模态 函数question_save(){
× New Question Modal function question_save(){
$.ajax({
url : "<?php echo base_url('Mainx/insert_question_header');?>",
crossDomain: true,
contentType: "application/x-www-form-urlencoded",
method: "POST",
data: { name: 'question_header'},
dataType: 'json',
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>',
success: function(data){
//alert('data save');
},
error: function (jqXHR, textStatus, errorThrown){
alert('Error adding');
}
});
}
问题标题:
Question Header:
最后,在我的控制器上,并在我的视图下显示我在输入中键入的值.
And lastly from my controller and display the value that i type in my input under my view.
public function insert_question_header(){
$insert_header = array(
'question_header'=> $this->input->post("question_header")
);
//$this->db->insert('tb_question_header', $insert_header);
echo json_encode($insert_header);
redirect('Mainx/question_form/success' );
}
推荐答案
嘿伙计们刚刚找到了答案.感谢您的所有建议.
hey guys just found the answer. Thank you for all your suggestions and advice.
<script type="text/javascript">
function q_header() {
var question = document.getElementById('question').value;
$.ajax({
url: "<?php echo base_url('Mainx/insert_question_header');?>",
type: "post",
data: {'<?php echo $this->security->get_csrf_token_name(); ?>':'<?php echo $this->security->get_csrf_hash(); ?>',"question":question},
success: function(){
alert("success");
},
error:function(){
alert("failure");
}
});
}
</script>
我尝试使用此代码,而不是使用question_header将其更改为问题.即使您将$ config [csrf_protection] = TRUE设置为该值,它也将起作用.或$ config [csrf_generate] = TRUE; 这是我的最新答案.
I try this code and instead using question_header i change it to question. This also work even when you set your $config[csrf_protection]=TRUE; or $config[csrf_generate]=TRUE; this is my updated answer.
这篇关于Codeigniter 3中禁止发布url 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!