[thelist] iframe needed for progress meter?

Volkan Özçelik volkan.ozcelik at gmail.com
Sun Feb 17 23:48:01 CST 2008


Hi Bill,

On Feb 17, 2008 5:52 PM, Bill Moseley <moseley at hank.org> wrote:

> Maybe of the example for upload progress meters I see on line often
> use an iframe to post the form.  I think this was for browsers that
> might not handle AJAX requests after posting the form.


AFAIK, you cannot serialize binary content of < input type="file" /> through
a pure XmlHttpRequest post.
Therefore you need an intermediate layer to send binary data, while the main
application continues to
track the progress.

This can be done, with a flash object behind, a java applet (possibly with
some security warnings) or with an IFRAME.

IFRAME solution is the simplest to implement in most cases.


> Firefox but I've also seen examples that don't use
> an iframe and claim to work in modern browsers.


May be if you enable

netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

and some other privileges it will be possible to upload files and track
progress with Firefox, though
1. I'm not sure
2. it will work only on Firefox.


> Does anyone know the specifics when a simple post (without an iframe)
> might not work?


In supporting browsers, a simple simple XmlHttpRequest post without an
iframe might not work if there is a timeout problem or if the server returns
any kind of error as the AJAX responseText (4xx and 5xx errors)

Also, most of the time, the user agent caches AJAX responses, so you have to
make sure that your response is an original (not cached) one.


> Actually, a number of the iframe implementations I looked at were not
> thought through -- two I tried when I manually stopped an upload (hit
> esc) the script continued to send ajax requests (I noticed this after
> about 10 minutes -- their poor test server had 600 requests by that
> time... ;)


I guess that AJAX requests are only for pinging the server for getting a
progress report of some sort.
The heavylifting of the file upload is done with the IFRAME. So the AJAX
pings will not hurt too much.
Actually it is technically difficult to detect whether an upload has stopped
from the server side.

A better implementation may have a "cancel" button on the GUI, where hitting
"cancel" will inform the server
(via an AJAX request) to close file upload stream and stop pinging the
upload progress.


> The other thing I don't like about the iframe approach is if the
> posted form fails validation it's not as easy to just return the form
>

I think this can be sorted out with some additional work -- may be some
extra client-side validation.

Hope that helps,
-- 
Volkan Ozcelik
+> linkibol.com - in seek for quality links : http://www.linkibol.com/
+> Going solo in Turkish: http://www.fikribol.com/donkisot/
+> My projects/studies/trials/errors : http://www.sarmal.com/
+> Sardalya JavaScript Library: http://www.sarmal.com/sardalya/



More information about the thelist mailing list