Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Upload a file using Ajax (See related posts)

This code is categorised as Ajax because it "fits within my definition of Ajax" as explained from the Ajax File Upload [openjs.com] article.

   1  
   2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   3    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   4  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   5    <head>
   6      <title>File upload</title>
   7      <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
   8      <script type="text/javascript">
   9      //<![CDATA[
  10        function init() {
  11  	document.getElementById('file_upload_form').onsubmit=function() {
  12                                    //'upload_target' is the name of the iframe
  13  	  document.getElementById('file_upload_form').target = 'upload_target'; 
  14  	  }
  15    }
  16    window.onload=init;
  17      //]]>
  18      </script>
  19    </head>
  20    <body>
  21      <form id="file_upload_form" method="post" enctype="multipart/form-data" action="/p/file_upload.cgi">
  22      <input name="myfile" id="myfile" size="27" type="file" /><br />
  23      <input type="submit" name="action" value="Upload" /><br />
  24      <iframe id="upload_target" name="upload_target" src="" style="width:0;height:0;border:0px solid #fff;"></iframe>
  25      </form>
  26    </body>
  27  </html>

You need to create an account or log in to post comments to this site.


Click here to browse all 5545 code snippets

Related Posts