javascript / jQuery在新标签中发布和查看pdf

时间:2017-11-08 14:47:31

标签: javascript jquery

我有一个javascript表单,在提交时会执行POST请求,生成并动态下载PDF。我想在新标签中查看此PDF文件。

这是我到目前为止所做的:

$.post({
    type: 'GET',
    url: target_url,
    data: 'content=' + JSON.stringify(editor.getValue()),
}).done(function(data){
    w = window.open('target="_blank"');
    w.document.open();
    w.document.write(data);
    w.document.close();
});

发布请求成功,并打开一个新标签,但填充了已编码/不可读的材料。如何在浏览器pdf viewer中打开结果?

1 个答案:

答案 0 :(得分:1)

您可能需要考虑使用plugin like pdf.js在浏览器中显示PDF。

我同意@Abhijeet WebDev您应该提供指向准备好的PDF的链接,并加载URL以在新标签页中打开/下载PDF。