【发布时间】:2014-12-30 22:51:45
【问题描述】:
简单的问题。我的 mojolicious 应用程序中生成了一个 .doc 文件。我想下载它。这是我的问题,我如何让浏览器下载它?
我正在使用 CPAN 模块 MsOffice::Word::HTML::Writer 来生成文档。
这是我的 mojolicious 应用程序中的子例程,它由 Jquery 中的 Ajax 请求调用:
sub down_doc {
my $self = shift;
my $doc = MsOffice::Word::HTML::Writer->new(
title => "My new Doc",
WordDocument => {View => 'Print'},
);
$doc->write("Content and Stuff");
my $save = $doc->save_as("/docs/file.doc");
$self->res->headers->content_disposition("attachment;filename=file.doc");
$self->res->headers->content_type('application/msword');
$self->render(data => $doc->content);
}
这是我在 Jquery 中的 Ajax 请求:
var request = $.ajax({
url: "/down_doc",
type: "post",
data: {'data': data},
});
request.done(function(response, textStatus, jqXHR) {
window.location.href = response;
});
我知道我的 Ajax“完成”处理程序是错误的,我只是在试验。如何让我的网页提示保存和下载 .doc 文件?
【问题讨论】:
标签: javascript jquery ajax