2015-12-18 38 views
0

我使用ajax和codeigniter来提交包含图像数据的表单。问题是控制器显示一些错误,如“不允许的关键字符”。我已经改变了配置文件。但仍然不起作用。请帮我解决这个问题。不允许的关键字符。在codeigniter中

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); 
        } 
    }); 
    }); 

位指示:

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

看这个http://stackoverflow.com/questions/4197976/codeigniter-disallowed-key-characters –

+0

已经尝试过这一点。但它不起作用。 – user5060801

+0

关于这个http://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax –

回答

0

尝试在config.php

$config['cookie_prefix'] = 'im_'; 
添加一个cookie前缀
0

一旦你发现了什么角色缺少你那么可以将其添加在这里

应用程序>配置> config.php文件

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&=?'; 

围绕线163

希望这有助于。

在网址上Ajax和试用BASE_URL()

url: 'controller/method/',