Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2008, 11:12 AM   PM User | #1
dpfreaks
New to the CF scene

 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
dpfreaks is an unknown quantity at this point
File Upload with pure AJAX?

Hi,

Is it possible to upload files using 100% ajax?[no iframe & hidden frames]?
dpfreaks is offline   Reply With Quote
Old 02-21-2008, 11:27 AM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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
liorean is offline   Reply With Quote
Old 02-21-2008, 12:50 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 02-21-2008 at 12:54 PM..
rnd me is offline   Reply With Quote
Old 02-21-2008, 12:54 PM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
What if the response is evaluated? eval()
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 02-21-2008, 01:36 PM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 03-13-2008, 01:10 AM   PM User | #6
Skyzyx
Regular Coder

 
Skyzyx's Avatar
 
Join Date: Aug 2002
Location: Silicon Valley, CA
Posts: 980
Thanks: 0
Thanked 0 Times in 0 Posts
Skyzyx is on a distinguished road
Here's one that utilizes MooTools, but no, it cannot be done purely with JavaScript.
http://digitarald.de/project/fancyupload/
__________________

Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.
Skyzyx is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:10 AM.


Advertisement
Log in to turn off these ads.