woodman
2008-May-05 11:13 UTC
prototype callback with response.getHeader(''Content-type'') == ''application/save''
I am using a php script that produce an application/save content : ----- $size = filesize($file_path); header("Content-Type: application/save"); header("Content-Length: $size"); header("Content-Disposition: attachment; filename=\"$file_name\""); header("Content-Transfer-Encoding: binary"); readfile($file_path); exit; ----- when called from ''new Ajax.Request(...'', the default browser behavior (ask the user to open or save the file) is skipped by prototype.js. how to keep the default browser behavior when response.getHeader(''Content-type'') == ''application/save'' --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Matt Foster
2008-May-05 15:43 UTC
Re: prototype callback with response.getHeader(''Content-type'') == ''application/save''
I don''t think you''re going to find a satisfactory solution to this. The XHR simply does not behave the way you''re expecting it to. If you want the user to download something of that nature, depending on your application state integrity, you could simply direct the browser to the downloadable URL. Or you could open a window and send that window to the URL, but in either case if you''re looking for that sort of behavior you aren''t going to find success with the XHR, just be smooth with the transition and it won''t be much of a difference. Thinking more on the idea, you could attempt to use an IFRAME but I am unsure how that would go, but worth a try. Good luck. On May 5, 7:13 am, woodman <forestier.pie...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using a php script that produce an application/save content : > ----- > $size = filesize($file_path); > header("Content-Type: application/save"); > header("Content-Length: $size"); > header("Content-Disposition: attachment; filename=\"$file_name\""); > header("Content-Transfer-Encoding: binary"); > readfile($file_path); > exit; > ----- > when called from ''new Ajax.Request(...'', the default browser behavior > (ask the user to open or save the file) is skipped by prototype.js. > > how to keep the default browser behavior when > response.getHeader(''Content-type'') == ''application/save''--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---