It is not possible. For security reasons, the browser does not allow javascript to upload files.
There are two normal workarounds for this problem:
- Perform the upload in an iFrame
- Use a flash plugin for uploading
I recently applied this tool to upload files asynchronously in my web page, and it works beatifully: http://valums.com/ajax-upload/
It creates an iFrame for you automatically, and posts the frame and and sends the resulting html (or json object) to an event handler. My page that receives the uploaded file, returns a json object describing the file, e.g. filename and a unique id, so that I can link the data that is posted on the main page to the uploaded file.
For security, I store the credentials of the user uploading the file, so when the form is posted I can validate that the user that posts the form is indeed the user that uploaded the file.