I''m not sure if this has been discussed before, but is it possible to get a file download as a response from Ajax.Request? I know you can have response txt or xml, but how would I go about requesting a file download? Currently I''m requesting the download like this: window.location = ''http://www.mysite.com/pdf_reports.php?id=1&mnt=05&yr=2005''; But as you know, this ties up the browser and gives me little control of the download. Any thoughts/experiences would greatly be appreciated! Ian Tyndall
Downloading is a function of the browser itself, not supported in the XMLHTTP object (you either get text or XML with it)... The only way I can think to initiate a file download without tying up your client instance, is to spawn a tiny popup window which initiates the download. But... that''s a popup. Maybe it can be done with an iFrame? But no, definitely not with XMLHTTP (unless I am just WAY wrong)... -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ian Tyndall Sent: Wednesday, March 15, 2006 2:43 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails-spinoffs] Ajax request for file downloads I''m not sure if this has been discussed before, but is it possible to get a file download as a response from Ajax.Request? I know you can have response txt or xml, but how would I go about requesting a file download? Currently I''m requesting the download like this: window.location = ''http://www.mysite.com/pdf_reports.php?id=1&mnt=05&yr=2005''; But as you know, this ties up the browser and gives me little control of the download. Any thoughts/experiences would greatly be appreciated! Ian Tyndall _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
iframes are generally the approach used On 3/15/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org> wrote:> Downloading is a function of the browser itself, not supported in the > XMLHTTP object (you either get text or XML with it)... > > The only way I can think to initiate a file download without tying up > your client instance, is to spawn a tiny popup window which initiates > the download. But... that''s a popup. Maybe it can be done with an > iFrame? > > But no, definitely not with XMLHTTP (unless I am just WAY wrong)... > > -----Original Message----- > From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ian > Tyndall > Sent: Wednesday, March 15, 2006 2:43 PM > To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > Subject: [Rails-spinoffs] Ajax request for file downloads > > I''m not sure if this has been discussed before, but is it possible to > get a file download as a response from Ajax.Request? I know you can > have response txt or xml, but how would I go about requesting a file > download? > Currently I''m requesting the download like this: > > window.location > ''http://www.mysite.com/pdf_reports.php?id=1&mnt=05&yr=2005''; > > > > But as you know, this ties up the browser and gives me little control of > > the download. > > Any thoughts/experiences would greatly be appreciated! > > Ian Tyndall > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > The information transmitted in this electronic mail is intended only for the > person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
> But as you know, this ties up the browser and gives me little controlof> the download.I''m wondering, what control of the download do you need? The browser and user should be in control of any file downloads... The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
oh, a download, thought he was referring to an upload. forget my post. :) On 3/15/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org> wrote:> > But as you know, this ties up the browser and gives me little control > of > > the download. > > > I''m wondering, what control of the download do you need? The browser and > user should be in control of any file downloads... > > The information transmitted in this electronic mail is intended only for the > person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Ryan Gahl wrote:>>But as you know, this ties up the browser and gives me little control >> >> >of > > >>the download. >> >> > > >I''m wondering, what control of the download do you need? The browser and >user should be in control of any file downloads... > >The information transmitted in this electronic mail is intended only for the >person or entity to which it is addressed and may contain confidential, >proprietary, and/or privileged material. Any review, retransmission, >dissemination or other use of, or taking of any action in reliance upon, >this information by persons or entities other than the intended recipient >is prohibited. If you received this in error, please contact the sender and >delete the material from all computers. > >_______________________________________________ >Rails-spinoffs mailing list >Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >Thanks for the responses everyone! Good idea about the iframe! > I''m wondering, what control of the download do you need? It would nice to be able to cancel downloads like you cancel a request: request.transport.abort(); It would also be nice to have multiple downloads asynchronously downloading at one time. Again thanks for the responses and the iframe idea! Ian Tyndall
Ian Tyndall wrote:> I''m not sure if this has been discussed before, but is it possible to > get a file download as a response from Ajax.Request? I know you can > have response txt or xml, but how would I go about requesting a file > download? Currently I''m requesting the download like this: > window.location > ''http://www.mysite.com/pdf_reports.php?id=1&mnt=05&yr=2005'';If the server delivers that with the http header Content-Type: application/binary then you should get the browser behavior you''re looking for. If, instead you have Content-Type: text/html or Content-Type: text/plain or something else the browser is prepared to render, then it will render the page. -- Raul
> If the server delivers that with the http header > > Content-Type: application/binary > > then you should get the browser behavior you''re looking for.Is that true with the XMLHTTP object? I was under the impression that it''s handling of responses is self contained from the browser (i.e. the browser has no idea when and what types of responses the XMLHTTP object is getting) Maybe the XMLHTTP object passes control back to the browser with that header? Is that what you''re saying? As I said, I COULD be wrong, but I''m gonna have to say no (and sorry but I''m too busy to actually test this). At any rate, even if the browser is notified and takes control away from the XMLHTTP object, that''s not what the OP wants. He wants total behind the scenes control of the download (almost sounds like he wants to build a javascript based download manager). And I''ll stick with my original answer and say it''s not possible. The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
No, because a) you''re right about XMLHTTP requests not being able to handle this and b) that information is totally wrong, if any, then it should be Content-Disposition: attachment, not Content-Type: application/binary - David Am 16.03.2006 um 15:18 schrieb Ryan Gahl:>> If the server delivers that with the http header >> >> Content-Type: application/binary >> >> then you should get the browser behavior you''re looking for. > > Is that true with the XMLHTTP object? I was under the impression that > it''s handling of responses is self contained from the browser (i.e. > the > browser has no idea when and what types of responses the XMLHTTP > object > is getting) Maybe the XMLHTTP object passes control back to the > browser > with that header? Is that what you''re saying? As I said, I COULD be > wrong, but I''m gonna have to say no (and sorry but I''m too busy to > actually test this). > > At any rate, even if the browser is notified and takes control away > from > the XMLHTTP object, that''s not what the OP wants. He wants total > behind > the scenes control of the download (almost sounds like he wants to > build > a javascript based download manager). And I''ll stick with my original > answer and say it''s not possible. > > The information transmitted in this electronic mail is intended > only for the > person or entity to which it is addressed and may contain > confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited. If you received this in error, please contact the > sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >