2015-12-18 56 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/',