使用Ajax下载并打开PDF文件
2022-08-30 05:29:03
我有一个生成PDF的操作类。已正确设置。contentType
public class MyAction extends ActionSupport
{
public String execute() {
...
...
File report = signedPdfExporter.generateReport(xyzData, props);
inputStream = new FileInputStream(report);
contentDisposition = "attachment=\"" + report.getName() + "\"";
contentType = "application/pdf";
return SUCCESS;
}
}
我通过Ajax调用来调用它。我不知道如何将此流传送到浏览器。我尝试了一些东西,但没有任何效果。action
$.ajax({
type: "POST",
url: url,
data: wireIdList,
cache: false,
success: function(response)
{
alert('got response');
window.open(response);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Error occurred while opening fax template'
+ getAjaxErrorString(textStatus, errorThrown));
}
});
上面给出了错误:
您的浏览器发送了此服务器无法理解的请求。