Page 1 of 1

File Uploadin by Ajax

Posted: Thu Oct 19, 2006 6:26 am
by mr00047
Hello

I want to know is there any way to upload a file using Ajax without submiting the page(also without using IFrame).

If you have a solution please provide a sample code.

Thanks.

Posted: Thu Oct 19, 2006 12:15 pm
by nickvd
I have a working example that works, however it uses the iframe method... There is no other way that I have found that will let you do a file upload, without using a reload, or an iframe... When I get home tonight, I can post a sample...

Posted: Thu Oct 19, 2006 1:06 pm
by Christopher
I do not believe that the actual upload can be done via xmlhttprequest. But the wrapper can be Ajax.

Posted: Thu Oct 19, 2006 1:13 pm
by nickvd
The way I have it working is very degradable... On page load, it removes the submit button and the file upload field, appends the iframe which has a document that replicates the file upload field and the submit button (future versions will use the dom to clone the existing fields), on the iframe page load, it replicates all the existing fields into the current (iframe) page, on submit, it will do the upload and reload the iframe, which causes the page to output more onload javascript which will call a function in the parent frame (the actual page).

It works very seamlessly, with or without javascript...

Posted: Thu Oct 19, 2006 7:43 pm
by Ambush Commander
Right. If JavaScript was allowed to upload files willy nilly, you'd be presented with a security threat.