Ext做文件上传的时候发现,如果上传成功后从后台取返回信息,出现错误。
- var importForm = new Ext.FormPanel({
- labelAlign:'right',
- buttonAlign:'right',
- frame:true,
- title: '',
- bodyStyle:'padding:5px 5px',
- width:450,
- url:'importAction.do?method=importAlarmRule',
- fileUpload: true,
- items: [{
- xtype: 'textfield',
- fieldLabel: '<bean:message key="aloes.message.resource.import.file" />',
- name: 'importFile',
- width: 270,
- height:20,
- allowBlank:false,
- blankText: '<bean:message key="aloes.message.resource.import.file.select" />',
- inputType: 'file'//文件类型
- }],
- buttons: [{
- text: '<bean:message key="button.save" />',
- handler: function() {
- importForm.getForm().submit({
- success: function(fileform, action){
- if(action.result.success == 'true'){
- Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){
- importWin.close();
- });
- }else if(action.result.failure == 'formatError'){
- Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info);
- }
- },
- failure: function(){
- Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />');
- }
- });
- }
- },{
- text: '<bean:message key="button.cancel" />',
- handler: function() {
- importWin.close();
- }
- }]
- });
- var importWin = new Ext.Window({
- id:'import-window',
- title: '<bean:message key="aloes.message.resource.import" />',
- closable:true,
- width:460,
- maximizable:false,
- modal:true,
- plain:true,
- items:[importForm]
- });
- importWin.show();
var importForm = new Ext.FormPanel({
labelAlign:'right',
buttonAlign:'right',
frame:true,
title: '',
bodyStyle:'padding:5px 5px',
width:450,
url:'importAction.do?method=importAlarmRule',
fileUpload: true,
items: [{
xtype: 'textfield',
fieldLabel: '<bean:message key="aloes.message.resource.import.file" />',
name: 'importFile',
width: 270,
height:20,
allowBlank:false,
blankText: '<bean:message key="aloes.message.resource.import.file.select" />',
inputType: 'file'//文件类型
}],
buttons: [{
text: '<bean:message key="button.save" />',
handler: function() {
importForm.getForm().submit({
success: function(fileform, action){
if(action.result.success == 'true'){
Ext.Msg.alert('<bean:message key="info.header" />', '<bean:message key="aloes.message.resource.import.success" />',function(){
importWin.close();
});
}else if(action.result.failure == 'formatError'){
Ext.Msg.alert('Error', '<bean:message key="aloes.message.resource.import.failed" />'+action.result.info);
}
},
failure: function(){
Ext.Msg.alert('<bean:message key="message.error" />', '<bean:message key="aloes.message.resource.import.failed" />');
}
});
}
},{
text: '<bean:message key="button.cancel" />',
handler: function() {
importWin.close();
}
}]
});
var importWin = new Ext.Window({
id:'import-window',
title: '<bean:message key="aloes.message.resource.import" />',
closable:true,
width:460,
maximizable:false,
modal:true,
plain:true,
items:[importForm]
});
importWin.show();
后台的java代码往前台送数据的时候:
resultStr.append("{'failure':'false','success':'true'}");
response.setContentType(" text/html;charset=utf-8 ");
response.getWriter().print(resultStr);
contentType必须为:" text/html;charset=utf-8 "
而不能为:" text/xml;charset=utf-8 "
否则前台会报错。
本文讨论了使用Ext框架进行文件上传时遇到的问题,特别关注于上传成功后,从后台获取返回信息时出现的错误。通过提供详细的JS代码示例,解释了如何正确设置文件上传功能及处理后台返回的数据,确保了上传操作的顺利进行。



2397

被折叠的 条评论
为什么被折叠?



