【发布时间】:2016-01-28 04:55:01
【问题描述】:
我想在浏览器中显示 pdf ajax 响应。问题是我无法直接打开 url,因为 pdf 是动态创建的,我该如何显示它。
$.ajax({
url: url,
type: "POST",
data: JSON.stringify(data),
processData: false,
contentType: "application/json; charset=UTF-8",
complete: function (response) {
console.log(response);
window.open("pdf.php","_blank");
}
});
PDF 响应是
%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 1265>>
PHP 代码
header('Cache-Control: public');
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="new.pdf"');
header('Content-Length: ' . strlen($data));
echo $data;
应感谢任何帮助。
【问题讨论】:
-
刚打开新窗口开始...把数据发布到新窗口。
-
您遇到了什么错误?如果直接把pdf.php放到浏览器的地址栏会怎样?如果它有效,那么 JS 也应该有效。
标签: javascript php jquery ajax pdf