2014-11-01 99 views
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的成功回应做些事情?如果是这样,我不知道是什么。

将不胜感激帮助

+0

做浏览器不是为节省Ajax请求显示弹出式的唯一的事? – a7omiton 2014-11-02 14:21:45

+0

^是这样的情况。在这种情况下将不得不重新调整我的请求。 – a7omiton 2014-11-02 14:31:06

回答

0

浏览器不会,如果你通过AJAX发送/接收文件的内容提示保存对话框,至少这是我学到了什么(除非你能在AJAX成功响应做些什么请求)。

这意味着做的是重定向到另一个网址