views:

38

answers:

5

I am looking for a ajax method that can be used to file upload. It will be super if I find a funtion that uses Prototype + Script.acul.us

A: 

File uploads are not possible using pure Ajax, because Javascript can't get direct access to the local file.

Tools like the jQuery form plugin work around this by generating an invisible iframe on the fly, and submitting to that.

There probably is a Prototype based, or framework independent solution for this as well.

Pekka
A: 

there is no native ajax support for this, however Uploadify does a workaround using flash (uses jquery but is able to be used with other api's since 2.0)

DoXicK
A: 

try: http://www.swfupload.org/

jebberwocky
A: 

As others have pointed out, javascript is not able to asynchronously upload files (otherwise javascript enabled sites could steal any file off your harddrive). The best approaches are:

  • A flash uploader, as already suggested
  • Or simulate an Ajax request using an iframe

The iframe approach means that it's the iframe which reloads, instead of the page displayed to your users, so that to the end user, the experience looks as if it's Ajax.

If you're using rails, which I gather you might be due to using prototype and scriptaculous, there's a plugin available which handles the tricky bits of this approach for you called responds_to_parent, It's been ages since I implemented this in a rails app myself, but step 6 from this blog looks like a good example of how to use it.

Jeremy