返回的附件与$就调用 [英] Return attachment with $.ajax call

查看:123
本文介绍了返回的附件与$就调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

感谢

解决方案

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

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

如果你需要一个POST请求:

 <形式的行动=/的SamplePage / ExportToExcel的方法=邮报>
    <输入类型=提交值=下载/>
< /形式GT;
 

当你使用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.

这篇关于返回的附件与$就调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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