title: upload file using jquery ajax
body: <p>I'm trying to upload a file with jquery but I don't want to refresh the page.</p>
  
  <p>I read some duplicate questions but they didn't solve my problem.</p>
  
  <p>please tell me if I'm wrong in using codes.</p>
  
  <pre><code>&lt;script src="js/jquery-1.8.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.form.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="js/myajax.js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>html code:</p>
  
  <pre><code>&lt;form id="uploadpic" action="func/uploader.php" enctype="multipart/form-data" method="post" onsubmit="sendAjax('uploadpic','#image_place'); return false;"&gt;
  &lt;label for="UserImage" class="fright"&gt;new pic&lt;/label&gt;
  &lt;div class="file-input width-100"&gt;
      &lt;input type="file" id="File1" class="choose-file" name="choose-file" onchange="javascript: document.getElementById('uploadpic').submit();" /&gt;
      &lt;span class="file-button"&gt;- - - - -&lt;/span&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and myajax.js:</p>
  
  <pre><code>function sendAjax(n,des,dataform){
      if(dataform==undefined) dataform = des;
      $(dataform).animate({opacity:0.5},100);
      var frm = $('#'+n);
          $.ajax({
          type: frm.attr('method'),
          url: frm.attr('action'),
          data: frm.serialize(),
          success: function (data) {
          $(des).html(data);
              $(dataform).animate({opacity:1},100);
          }
      });
      return false;
  }
  </code></pre>
  
  <p>thanks...</p>