Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Upload with pure AJAX?

    Hi,

    Is it possible to upload files using 100% ajax?[no iframe & hidden frames]?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Quote Originally Posted by dpfreaks View Post
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,376
    Thanks
    11
    Thanked 592 Times in 572 Posts
    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
    Last edited by rnd me; 02-21-2008 at 12:54 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    What if the response is evaluated? eval()
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,376
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by Kor View Post
    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)
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's one that utilizes MooTools, but no, it cannot be done purely with JavaScript.
    http://digitarald.de/project/fancyupload/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •