PDA

View Full Version : Success handler not getting called in file upload using extjs



rianinan
6 Oct 2010, 11:37 PM
I have a J2EE web app with a form where I upload a file to a location on a server. During the upload a waitMsg is shown to the user which should disappear once the upload is completed with a msgBox indicating the same. The code for the success case is also provided in the js file. However the upload works fine, but the waitMsg continues even after the upload at the server has completed.
The js code is given:


Ext.onReady(function(){

Ext.QuickTips.init();

var msg = function(title, msg){
Ext.Msg.show({
title: title,
msg: msg,
minWidth: 200,
modal: true,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
};

var fp = new Ext.FormPanel({
renderTo: 'fi-form',
fileUpload: true,
width: 500,
frame: true,
title: 'Upload XML Config File ',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select the xml File to upload',
fieldLabel: 'File',
name: 'file',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
}
}],
buttons: [{
text: 'Upload',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'uploadXML.htm',
waitMsg: 'Uploading your xml file...',
success: function(fp, o){
msg('Success', 'Processed file "'+o.result.file+'" on the server');
}
});
}
if (!validateFileExtension(Ext.getDom('form-file').value)) {
Ext.MessageBox.alert('Select another file',
'Only XML file, please.');
return;
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});

function validateFileExtension(fileName) {
var exp = /^.*\.(xml|XML)$/;
return exp.test(fileName);
}

}); Not sure what I am missing.
Thanks in advance.

Animal
6 Oct 2010, 11:47 PM
Probably missing reading the docs properly.

What does your response look like, and what do you set the Content-Type header to?

rianinan
7 Oct 2010, 4:23 AM
Probably missing reading the docs properly.

What does your response look like, and what do you set the Content-Type header to?

Thanks for the hints.. checked and found that issue was with the response.
Now it works very well (uploads to server and success message box pops up... ) with firefox, but gives a java script error "Syntax Error" with IE 6.0 on uploading. I checked the js file with JavaScript Lint, which says there are no warnings or errors. The issue is somewhere with the following piece of code...

if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'uploadXML.htm',
success: function(fp, o){
msg('Success', o.result.message);
}
});
}

Animal
7 Oct 2010, 4:30 AM
I suspect the issue is still with the response.

What does the response look like, and what HTTP headers do you send?

andredecotia
18 Oct 2010, 10:38 AM
Hey Animal, what's up mister!

Could you please have a look at post like this doubt -> http://www.sencha.com/forum/showthread.php?112877-EXTjs-success-and-waitMsg-messages-doubts...&p=526598#post526598 thank you so much you're the man!