title: File is not uploaded and gives me "You did not select a file to upload" when I m using jquery ajax method to call controller function of CI
body: <p>File is not uploaded and gives me "You did not select a file to upload" error when I m using jquery ajax method to call controller function of CodeIgniter.So please help me to resolve this error and upload file with ajax </p>
  
  <pre><code>//My View : 
  &lt;form  id="frm" name="frm" enctype="multipart/form-data"&gt;
  &lt;input type="file" name="userfile" id="userfile" size="20"/&gt; 
  &lt;input type="button" value="upload" id="upload" name="upload"/&gt;
  &lt;/form&gt;
  
  //calling button live method from view
  $('#upload').live("click", function ()
  {
  //calling jquery ajax
  $.ajax({
  type: "POST",
  url:"../user/usercontroller/do_upload", //calling controller function
  cache: true,
  success: function(data4)
  { 
  alert('in ajax'+data4);
  },datatype: "json"
  });
  });
  
  //My Controller:
  function do_upload()
  {
  $upload_dir ='./uploads/';
  $config['upload_path'] = realpath($upload_dir);
  $config['overwrite'] = TRUE;    
  $config['allowed_types'] = '*';
  $config['encrypt_name']  = true;
  $config['remove_spaces']  = TRUE;
  $this-&gt;load-&gt;library('upload', $config);
  if (!$this-&gt;upload-&gt;do_upload('userfile'))
  {
  print_r($this-&gt;upload-&gt;display_errors());
  }    
  else
  {
  print_r($this-&gt;upload-&gt;data());
  }            
  }
  </code></pre>