使用 ajax,我得到的响应是 PDF base64 数据。在此示例中,我在新窗口中显示它,而不是我想在模式弹出窗口中显示 PDF。有什么办法吗?
$.ajax({
type : "POST",
url : getPrintablePDF,
dataType : "json",
contentType : 'application/json; charset=utf-8',
data : JSON.stringify(params),
success : function(data) {
//console.log(data);
var myResponse = eval(data);
window.open('data:application/pdf;base64,' + myResponse.base64EncodedResponse);
}
});
最佳答案
尝试使用 <object />
或 <embed />
或使用 <iframe />
我用 <iframe />
举了一个例子因为所有浏览器都支持它。
$.ajax({
type : "POST",
url : getPrintablePDF,
dataType : "json",
contentType : 'application/json; charset=utf-8',
data : JSON.stringify(params),
success : function(data) {
var myResponse = eval(data);
$("<iframe />") // create an iframe
// add the source
.attr('src', 'data:application/pdf;base64,' + myResponse.base64EncodedResponse)
.appendTo('.modal-body'); // append to modal body or wherever you want
}
});
关于javascript - 我想在模态窗口中显示 PDF ajax 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14153207/