View Full Version : File Upload with pure AJAX?
dpfreaks
02-21-2008, 12:12 PM
Hi,
Is it possible to upload files using 100% ajax?[no iframe & hidden frames]?
liorean
02-21-2008, 12:27 PM
Is it possible to upload files using 100% ajax?[no iframe & hidden frames]?Not really. You can send files from JavaScript, but there's no way to get a handle to a local file from JavaScript. (I'm not actually sure what I just said is correct. I know browsers prevent JavaScript to mess with file controls, so I don't expect it's possible to extract the file out of file control as an object in JavaScript.) The best way is to use an iframe with a form with a file control to upload the file. You can use XHR to check the completion status of the file upload though.
rnd me
02-21-2008, 01:50 PM
you can load and you can save, but youll have trouble doing both on the same page for security reasons.
firefox3 will allow you read the file data from a file input tag.
if you have rw permissions, you can upload a file using an ajax PUT.
ie will let you load and save files to "local zones".
IE allows access to local files using the file system object library.
firefox lacks this, and while you can read local files, if you are on a locally saved page, you wont have permission to PUT that data to another domain.
once FF3 is out, you could piece together a cross-browser interface for both techs.
one last note, you could write a script as a greasemonkey user script in FF to get around the security limits, but that will certainly reduce your user base (if that matters).
note that you shouldn't need a hidden frame, but will need a visible form to present a file input
What if the response is evaluated? eval()
rnd me
02-21-2008, 02:36 PM
What if the response is evaluated? eval()
what response are you talking about?
xdomain requests are terminated via exception before a response is issued.
.src script tags don't provide raw access to the 'response' text at the url.
i have tried overriding the Error object, Object.eval, and other objects to try to leach data from script tags. no avail.
im confused, but hopefully you know something i don't! (that would be great)
Skyzyx
03-13-2008, 02:10 AM
Here's one that utilizes MooTools, but no, it cannot be done purely with JavaScript.
http://digitarald.de/project/fancyupload/
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.