我正在使用带有codeigniter的ajax来提交包含图像数据的表单。问题是控制器显示一些错误,例如"禁止关键字符"。我已经更改了配置文件。但仍然无法正常工作。请帮我解决这个问题。
Ajax电话:
$("form#wall_add").submit(function() {
var m_data = new FormData();
m_data.append( 'id', $('input[name=id]').val());
m_data.append( 'desc', $('input[name=desc]').val());
m_data.append( 'notify', $('input[name=notify]').val());
m_data.append( 'dcrp', $('textarea[name=dcrp]').val());
m_data.append( 'img', $('input[name=post]')[0].files[0]);
$.ajax({
url: '<?php echo base_url();?>controller/method/',
data: m_data,
mimeType: "multipart/form-data",
contentType: false,
processData: false,
type: 'POST',
success: function(result)
{
$('#posts').html(result);
}
});
});
contoller:
public function method(){
$data['added_content'] = $this->model->ins();
$this->load->view('ajax_get_added',$data);
}
型号:
date_default_timezone_set('Asia/Calcutta');
$date = date("Y-m-d H:i:s", time());
$fid = $this->input->post('id');
$desc = $this->input->post('dcrp');
$dtl = $this->input->post('desc1');
$notify = $this->input->post('notify');
$this->load->helper('date');
$config['upload_path'] = './img/post_images/family/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$field_name ="img_post";
$rgpic="0";
if ( !$this->upload->do_upload($field_name))
{
$error = $this->upload->display_errors();
$data['error']=$error;
}
else
{
$data = $this->upload->data();
$regpicname=$data['file_name'];
$rgpic="1";
}
if($rgpic!=0)
{
$data = array('date'=>$date,
'status'=>'A',
'img'=>'img/post_images/family/'.$regpicname,
'desc'=>$desc.$dtl,
'id'=>$fid,
'notify'=>$notify
);
}
else{
$data = array(
'date'=>$date,
'status'=>'A',
'desc'=>$desc.$dtl,
'id'=>$fid,
'notify'=>$notify
);
}
答案 0 :(得分:0)
一旦找到了缺少的字符,就可以在此处添加
应用程序&gt; config&gt;的config.php
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&=?';
第163行
希望这有帮助。
将您的网址放在ajax上,尝试使用base_url()
url: 'controller/method/',