I need to upload files using ajax which has to be supported in IE9. I was using FormData as mentioned here. My code looks like this:
var files = new FormData
Unfortunately you cannot use Ajax (XMLHttpRequest
in other words) for sending files, but you can implement a similar behavior using the <iframe/>
with a <form method="post" enctype="multipart/form-data"/>
that contains an <input type="file"/>
which sends a user chosen file using the "natural" way. You can use javascript to call the form.submit()
then poll that <iframe/>
from parent document to check whether the file upload process is done.
jQuery
has a lot of cool plugins for getting this job done, there is my favorite one, for example.