In this situation, I just do a normal (non-Ajax) form POST with the
`target` attribute set to reference a hidden iframe, triggering the
submit via code -- something like this: http://jsbin.com/omuge3 (in
that example the iframe is hidden in a somewhat naive way; I'm not at
my main workstation and don't immediately recall the full markup I
use). Since the iframe is hidden and therefore won't show the user any
errors that may occur, I do two further things not shown in that JSBin
post: 1. I send a cookie in the response that tells the client-side
code the response has come back and gives a success flag or error
message (polling for the cookie on the client), and 2. I poll the
content of the iframe in case an error occurs even sending the request
(in which case I won't see the cookie). Works a treat, all the user
sees is a download dialog (on success) or an error message from my app
(on failure). I only do stuff like this in apps where JavaScript is
already a requirement, of course. Keep meaning to do a blog post on
this technique, but the above covers the basics.

T.J. Crowder
Independent Software Consultant
mail: tj / crowder software / com
web: www / crowder software / com

On Sep 10, 7:19 pm, Blaine <blaine.simp...@admc.com> wrote:
> When one assigns to window.location, the web browser automatically
> invokes attachment-handling according to the contentType if the
> response's Content-Disposition is set to "attachment".  The same thing
> happens if the request is elicited by a traditional form submittal or
> triggering an href linked to the Content-Disposition==attachment
> target.
> My use case seem pretty simple to me.  I need to post a bunch of data
> via postBody, and the response will be an attachment.  Both parts are
> prosaic and simple, but web searches find nothing on the Internet of
> anybody trying to do both of these things.  Seems that as soon as Ajax
> is introduced, you lose the ability for the browser to automatically
> handle attachments, and I find no ability to handle them manually via
> w3c DOM API or PrototypeJS API  (viz. to have the browser open the
> Open/Save-As pop-up).
> To maybe prevent a couple exchanges...  I do need to use "post" method
> due to the nature of the data (that the attachment will be generated
> from).  I do not want to hold/cache data on the server for a
> subsequent traditional fetch:  This is clean and atomic as a single
> post transaction and I don't want to introduce memory contention
> issues and the opportunity for memory leaks.  I tried PrototypeJS's
> form.request() in hopes that if no callback was specified maybe the
> browser's default handler would be used... but it ain't.

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to