你如何调用一个文件下载使用link_to_remote在轨? [英] How do you invoke a file download with link_to_remote in rails?

查看:96
本文介绍了你如何调用一个文件下载使用link_to_remote在轨?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够调用使用链接到远程轨文件下载。我的工作没关系的链接,它看起来是这样的:

I'd like to be able to invoke a file download from rails using link to remote. I have the link working okay,it looks like this :

link_to_remote image_tag("icons/ppt_48.png"),
   :url => formatted_element_path(@element, :ppt),
   :method => :get,
   :with => "'stoplight=' + $F('stoplight')"

响应包含了适当的文件,但是当响应在下载对话框不会显示。有没有办法来调用下载的对话?我需要这在IE和工作火狐

The response contains the proper file, but the download dialogue doesn't appear when the response comes in. Is there a way to invoke the download dialogue? I need this to work in IE as well as firefox

THX,

-C

推荐答案

从ParticleTree 文章一>提到了一个简单而有效的解决方案,不涉及AJAX 所有,但也导致文件下载无需离开当前页面的用户:

An article from ParticleTree mentions a simple and effective solution that doesn't involve AJAX at all, but does cause a file to download without the user leaving the current page:

<form id="super_form" method="post" action="/file/">
    <input type="hidden" id="download" name="download" />
</form>

$('download').value = 'top10';
$('super_form').submit();

这并不直接回答你关于如何有通过Ajax请求文件下载的问题,但我认为这会给你的最终用户,你要寻找的经验。

This doesn't directly answer your question about how to have a file download via an AJAX request, but I think this will give your end-user the experience you're looking for.

这篇关于你如何调用一个文件下载使用link_to_remote在轨?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆