通过发送POST参数在ExtJS 4中显示PDF
Display a PDF in Ext JS 4 by sending POST parameters
要使用Ext JS 4应用程序显示PDF文档,我使用以下代码(GET请求):
Ext.create('Ext.window.Window', {
items: {
xtype: 'component',
autoEl: {
tag: 'iframe',
src: 'getDocument.do?id=' + myDocumentId
}
}
}).show();
现在我想显示一个PDF,它需要通过POST请求发送一个复杂的JSON对象才能生成。我尝试发送一个带有JSON参数"myJsonParameter"的"ajax请求"并显示结果。是否可以在窗口中显示request.responceText(包含我的PDF的二进制数据)?
Ext.Ajax.request({
url: 'getDocument.do',
jsonData: myJsonParameter,
binary: true,
success: function(response, options){
Ext.create("Ext.window.Window", {
items: {
xtype: 'component',
html: '<embed width=100% height=100%' +
' type="application/pdf"' +
' src="data:application/pdf;' +
response.responseText +
'"></embed>'
}
}).show();
}
});
我也试过这个;但渲染显示特殊字符,而不是PDF文档:
Ext.create("Ext.window.Window", {
items: {
xtype: 'component',
loader: {
url: 'getDocument.do',
autoLoad: true,
ajaxOptions: {
binary: true,
jsonData: myJsonParam,
headers: "application/pdf"
}
}
}
}).show();
备注:我不知道这是不是一个好方法;欢迎任何帮助。
提前感谢!
目前最好的解决方案是接收POST参数的iframe(但我找不到以JSON格式发送{toto:‘abc’}的方法)。
Ext.create('Ext.window.Window', {
items: [{
xtype: 'component',
autoEl: {tag: 'iframe', name: 'myIframe'}
},{
xtype: 'form', hidden: true,
listeners: {
afterrender: function(form){
form.getForm().doAction('standardsubmit',{
target : 'myIframe', method : 'POST',
params: {toto: 'abc'},
url : '../myPath/getDocument.do'
});
}
}
}]
}).show();
var that = this;
Ext.Ajax.request({
url: '<app url>',
timeout: 120000, // optional
scope : that,
params: {
investor_id:investor_id,
scenario_id:scenario_id,
prog_id:prog_id,
action: 'po',
operation: 'generate'
},
failure: function(response) {
//handle failure condition
},
success: function(response){
var responseObj = Ext.JSON.decode(response.responseText);
var isSuccess = responseObj.success;
var errorMsg = responseObj.errorMsg;
var url = responseObj.url;
if( isSuccess=="false" ) {
//handle failure condition
} else {
//url
var popUp = Ext.create('Ext.window.Window', {
//header:false,
height: 800,
modal:true,
width: 1024,
layout:'anchor',
anchor:"100% 100%",
title:'Proposal Output',
maximizable: true,
minimizable: true
});
popUp.add({html: '<iframe height="730", width="1000" src="'+ url +'"></iframe>'});
popUp.add({
xtype: 'button',
width: '80',
cls: 'close-button',
handler: function(){
var win = Ext.WindowManager.getActive();
if (win) {
win.close();
}
}
});
popUp.show();
}
}
});
我们使用以下代码生成,请尝试。
相关文章:
- 文本字段显示它是有效的,即使它在ExtJS中是无效的
- 由于本地存储代理,Extjs网格面板最多显示25行.如何更改此限制值
- 通过发送POST参数在ExtJS 4中显示PDF
- extjs在chrome中可以正常工作;不要在firefox或ie中显示任何内容
- ExtJS显示对象属性
- 如何在ExtJs中显示网格上的线数
- ExtJs组合框显示字段编码
- Extjs 3,Borderlayout'不要显示北方
- ExtJS DataView只显示最后一个JSON元素
- 如何在extjs或jquery中显示JSON数据
- Extjs 网格列 - 组合在值更改后显示键而不是值
- 如何使 ExtJS 拖放树仅复制 - 而不是从显示中删除项目
- Ext.Window 在 extjs 3.4 中显示当前打开窗口后面的方法打开窗口
- Extjs 窗口在 IE 中不能很好地显示元素
- 在 ExtJS 组件中显示富文本
- ExtJS 5:显示字段绑定性能
- ExtJS 4 组合框在表单绑定上显示值字段而不是显示字段
- 如何在显示extjs窗口后调用jQuery
- Extjs显示网格表
- ExtJs.显示空网格的最简单方法