2
我想在浏览器中显示pdf ajax响应。问题是我无法直接打开网址,因为pdf是动态创建的,我该如何显示它。在浏览器中显示ajax响应的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;
任何帮助,应该理解。
只要打开新的窗口中启动...张贴数据到新窗口。 – epascarello
你有什么样的错误?如果将pdf.php直接放到浏览器的地址栏上会发生什么?如果它有效,那么JS应该也能工作。 – Stepashka