I have gone through many answers
How to upload file using ajax in codeigniter File upload in codeigniter using ajax
which does not work with my code.
I want to upload word pdf img any sort of file using ajax.
This is my code:
Controller:
public function saveDetailData()
{
    $rowId = $this->input->post('rowId',true);
    $rowData = $this->input->post('rowData',true);
    $rowColumn = $this->input->post('rowColumn',true);
    $detailTableName = $this->input->post('detailTableName',true);
    if($rowColumn == 'attachment'){
        $filename2 = 'Query_'.rand(0,999999);
        if( ! is_dir('uploads') ){mkdir('uploads',0777,TRUE); };      
        $path='uploads/queries/';        
        $imgtmpname=$_FILES['rowData']['tmp_name'];
        $name = $_FILES["rowData"]["name"];
        $ext = end((explode(".", $name)));
        $fullpath= $path .$filename2.'.'.$ext;
        $filename = $filename2;
        move_uploaded_file($imgtmpname,$fullpath);
        if ($ext <> '')
       {
        $fields = array(
                'attachment' => $fullpath
              );
       }
       else
       {
        $fields = array(
                'attachment' => ''
              );
       }
    }
    $this->user_model->saveDetailData($rowId,$fields, $detailTableName);
    echo "Successfully Saved";    
}
View:
<?php echo form_open_multipart('editMatter');?>
<input onfocusout="saveDetailData1('<?php echo $detail->id; ?>',$(this).attr('name'),'attachment' )" type="file" id="attachment_<?php echo $detail->id; ?>" name="attachment_<?php echo $detail->id; ?>" value="">
<script>
  function saveDetailData1(rowId,rowData,rowColumn) {
   attachment = new FormData( $('#'+rowData)[0] );
   $.ajax({
    type: "POST",
    url: "<?php echo base_url('user/saveDetailData')?>",
    data: {  '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>',
                                                'rowId': rowId,
                                                'rowData' :attachment,
                                                'rowColumn' :rowColumn,
                                                'detailTableName': 'tbl_mattersdetail',
                                              },
                                        dataType:"JSON",
                                        mimeType: "multipart/form-data",
                                        contentType: false,  
                                        cache: false,  
                                        processData:false,  
                                        success: function(response){ 
                                          //alert(response);
                                        }
         });
     }
  </script>
 
    