title: Insert data with upload image in ajax and codeigniter
body: <p>The code is given below</p>
  
  <p>For View</p>
  
  <pre><code>&lt;input type="text" name="name" id="name" class="input_field" /&gt;    
  &lt;input type="file" name="userfile" id='img_upload' /&gt;
  </code></pre>
  
  <p>Ajax Code</p>
  
  <pre><code>dataString = $("#student_info_form").serialize();
  $.ajax ({
      type    : "POST",
      url     : "&lt;?php echo base_url();?&gt;sms_con/add_student_info",
      data    : dataString,
      cache   : false,
      success : function(data){
  
      }
  });
  return false;
  </code></pre>
  
  <p>Controller Code</p>
  
  <pre><code>$config['upload_path'] = './uploads/';
          $config['allowed_types'] = 'gif|jpg|png';
          $config['max_size'] = '800';
          $config['max_width']  = '1024';
          $config['max_height']  = '768';
  
          $this-&gt;load-&gt;library('upload', $config);
  
          if (!$this-&gt;upload-&gt;do_upload("userfile"))
          {
              $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
              print_r($error);
          }
          else
          {
              $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
              $img =  $data ['upload_data']['file_name'];
              $data = $this-&gt;sms_model-&gt;add_student_info($img);
          }
  </code></pre>
  
  <p>But When i sebmit the form then i can see the error messsage is " <strong>You did not select a file to upload</strong> ";</p>
  
  <p>How to insert data with upload image via ajax.</p>
  
  <p>Please any help? </p>