0
我想通过AJAX POST下载表单提交的excel文件,但是当使用舞者send_file
方法时,我没有收到提示保存文件。下载Dancer中的excel文件 - jQuery AJAX
请参阅以下内容:
路线:
post '/:date' => sub {
my $report_date = param('date');
my $data = param('stuff');
my $rep = $report->build($report_date, $data);
return send_file("reports/$rep", content_type => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
};
在该路线的build
方法一旦创建它返回的文件名。 Ajax请求的样子:
$('#report').submit(function(event){
event.preventDefault();
$.ajax({
'url': $(this).attr('action'),
'type': 'POST',
'data': {stuff: ...},
'success': function(res){
console.log(res);
}
});
以上的console.log不返回任何内容,但是我得到的回应似乎好,用Excel文件中的内容,但没有提示:
Connection:Keep-Alive
Content-Disposition:attachment; filename="10-2014_1414869186.xlsx"
Content-Length:7161
Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Date:Sat, 01 Nov 2014 19:13:06 GMT
Keep-Alive:timeout=5, max=100
我是否需要为AJAX的成功回应做些事情?如果是这样,我不知道是什么。
将不胜感激帮助
做浏览器不是为节省Ajax请求显示弹出式的唯一的事? – a7omiton 2014-11-02 14:21:45
^是这样的情况。在这种情况下将不得不重新调整我的请求。 – a7omiton 2014-11-02 14:31:06