返回的附件与$就调用附件

由网友(走散在风中)分享简介:我有我的网页的iframe,而iframe中我执行code:$。阿贾克斯({网址:/的SamplePage / ExportToExcel',异步:假的,数据:相提并论,键入:POST});响应返回正常,但是我不明白保存附件对话框中,没有任何反应......为了把事情说清楚,头都很好(内容处置,MIME类型等),因为...

我有我的网页的iframe,而iframe中我执行code:

  $。阿贾克斯({
    网址:/的SamplePage / ExportToExcel',
    异步:假的,
    数据:相提并论,
    键入:POST
});
 

响应返回正常,但是我不明白保存附件对话框中,没有任何反应......为了把事情说清楚,头都很好(内容处置,MIME类型等),因为当我执行,出口使用普通的表单提交它的工作原理。看来,它是与AJAX调用。将它的工作不知何故?

感谢

解决方案

使用AJAX时,你不会得到另存为对话框。如果你想获得这个对话框只是提供一个正常的链接下载文件:

 < A HREF =/的SamplePage / ExportToExcel>下载< / A>
 

如果你需要一个POST请求:

 <形式的行动=/的SamplePage / ExportToExcel的方法=邮报>
    <输入类型=提交值=下载/>
< /形式GT;
 
Excel第一列下拉菜单选择后列自动变更

当你使用AJAX来下载这个文件的内容被检索的成功回调文件,但没有太多,你可以用它做:你不能将其保存到客户端电脑,你不能另存为对话框

I have an iframe on my page, and inside that iframe I execute code:

$.ajax({
    url: '/SamplePage/ExportToExcel',
    async: false,
    data: par,
    type: 'POST'
});

Response is returned fine, however I don't get 'SAVE ATTACHMENT' dialog, nothing happens... To make things clear, headers are fine (content disposition, mime type etc,), as when I execute that export using plain form submission it works. It seems that it has something to do with ajax call. Will it work somehow?

Thanks

解决方案

You won't get the Save As dialog when using AJAX. If you want to get this dialog simply provide a normal link to the download file:

<a href="/SamplePage/ExportToExcel">download</a>

or if you need a POST request:

<form action="/SamplePage/ExportToExcel" method="post">
    <input type="submit" value="download" />
</form>

When you use AJAX to download a file the contents of this file is retrieved at the success callback but there's not much you can do with it: you cannot save it to the client computer and you cannot get Save As dialog.

阅读全文

相关推荐

最新文章