我正在将动态生成的PDF从服务器流式传输到前端。 PDF不会在Chrome中显示任何问题,但会在IE11中生成此错误。
预期为DOCTYPE。考虑添加有效的HTML5文档类型:“!DOCTYPE html”
PDF是动态生成的,并在成功时返回GUID,然后在AJAX成功中使用该GUID打开到新PDF的链接。
在前端:
$.ajax({
url: "myURL",
method: "POST",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: The data used to create the PDF on the server,
success: function (result) {
window.location.href = "newURL?fileIdentifier=" + result;
},
error: function (error) {
console.log(error)
}
关于后面的代码:
var pdfFilePath = string.Format("{0}\\{1}.pdf", tempWorkPlanDirectory, fileIdentifier);
var fileBytes = File.ReadAllBytes(pdfFilePath);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline; filename=\"" + fileName + ".pdf\"");
Response.OutputStream.Write(fileBytes, 0, fileBytes.Length);