如何从jQuery的下载Excel中获得Ajax请求 [英] How to download excel from jQuery get ajax request

查看:793
本文介绍了如何从jQuery的下载Excel中获得Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring MVC的视图,它提供了一个Excel文件,不过,我现在已经修改了流程,使用户得到一个模式对话框中,他们可以选择下载的Excel之前的一些选项。这些选择的选项被发送到图。

I have a spring MVC view which provides an excel file, however, I've now modified the process so that the user gets a modal box in which they can select some options before downloading the excel. These selected options are sent to the view.

我的要求是这样的

$.get("downloadExcel", {  
    'foo': 'bar'
});

当该请求是由我期望能够下载的文件,然而,情况并非如此。尽管从上述请求的响应头是:

When that request is made I expect the file to be downloaded, however, that is not happening. Even though the response headers from the above request are:

Cache-Control:private, must-revalidate
Content-disposition:attachment; filename=filename.xls
Content-Language:en-US
Content-Type:application/vnd.ms-excel; charset=ISO-8859-1
Pragma:private
Server:Jetty(6.1.14)
Transfer-Encoding:chunked 

注意:一切运作良好时,我删除对话框,请求不再是一个Ajax请求。

Note: All works well when I remove the dialog box so the request is no longer an ajax request.

问题

有没有一种方法来获取通过Ajax请求excel文件?

Is there a way to fetch excel file via an ajax request?

推荐答案

使用Ajax响应你不能做到这一点。你要么需要重定向浏览器或渲染隐藏iFrame在页面开始下载。

You can't do this using an Ajax response. You either need to redirect the browser or render a hidden iFrame in the page to initiate the download.

这篇关于如何从jQuery的下载Excel中获得Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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