1
目标:显示pdf文件,作为服务器在新窗口中使用烬的响应收到。无法在浏览器中使用余烬阅读pdf内容
代码在路由文件:
actions: {
pdfClick(assessmentId) {
var result = [];
return new Ember.RSVP.Promise(function (resolve, reject) {
Ember.$.ajax({
type: 'GET',
url: 'http://localhost:4200/abc/secured/rest/questions/166',
success: function (data) {
var winlogicalname = "detailPDF";
var winparams = 'dependent=yes,locationbar=no,scrollbars=yes,menubar=yes,' +
'resizable,screenX=50,screenY=50,width=850,height=1050';
var detailWindow = window.open("content-type:application/pdf");
detailWindow.document.write(data);
},
error: function (request, textStatus, error) {
console.log(error);
}
});
});
}
}
困惑:
var detailWindow = window.open("content-type:application/pdf");
detailWindow.document.write(data);
在window.open,我们设置内容类型为application/PDF,然后我们什么时候尝试写入数据(从服务器收到的PDF文件的字节流),垃圾数据出现在新窗口中。
如果我通过Chrome浏览器访问该服务,Chrome能够显示PDF,但如果我使用ember ajax访问相同的服务,我无法在新窗口中显示PDF。