这是代码。 “core/bcsheet.php”返回PDF文档,但ajax显示为html代码。如何向用户显示 PDF?
function ajaxPost() {
form = $("#dbview");
formData = form.serialize();
formUrl = "core/bcsheet.php";
formMethod = form.attr('method');
$.ajax({
url: formUrl,
type: formMethod,
dataType: "html",
cache: false,
data: formData,
success: function (html) {
var win = window.open('', 'childWindow', 'location=yes, menubar=yes, toolbar=yes');
win.document.open();
win.document.write(html);
// win.print();
win.document.close();
//win.close();
}
});
};
最佳答案
我会在新窗口中打开 URL,并在通过 print()
传输内容的同时为脚本添加 pdf header 。
http://php.net/manual/de/function.header.php
关于javascript - 打开为 PDF ajax 返回的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249617/