title: XMLHttpRequest POST multipart/form-data
body: <p>I want to use XMLHttpRequest in JavaScript to POST a form that includes a file type input element so that I can avoid page refresh and get useful XML back.</p>
  
  <p>I can submit the form without page refresh, using JavaScript to set the target attribute on the form to an iframe for MSIE or an object for Mozilla, but this has two problems. The minor problem is that target is not W3C compliant (which is why I set it in JavaScript, not in XHTML). The major problem is that the onload event doesn't fire, at least not on Mozilla on OS X Leopard. Besides, XMLHttpRequest would make for prettier response code because the returned data could be XML, not confined to XHTML as is the case with iframe.</p>
  
  <p>Submitting the form results in HTTP that looks like:  </p>
  
  <pre><code>Content-Type: multipart/form-data;boundary=&lt;boundary string&gt;
  Content-Length: &lt;length&gt;
  --&lt;boundary string&gt;
  Content-Disposition: form-data, name="&lt;input element name&gt;"
  
  &lt;input element value&gt;
  --&lt;boundary string&gt;
  Content-Disposition: form-data, name=&lt;input element name&gt;"; filename="&lt;input element value&gt;"
  Content-Type: application/octet-stream
  
  &lt;element body&gt;
  </code></pre>
  
  <p>How do I get the XMLHttpRequest object's send method to duplicate the above HTTP stream?</p>