buttons: [{
            text: 'Save',
            handler: function(){
                if(fp.getForm().isValid()){
                fp.getForm().submit({
                    url: 'file-uploadServlet',
                    waitMsg: 'Uploading your photo...',
                    success: function(fp, o){
                        msg('Success', 'Processed file "'+o.result.file+'" on the server');
                    }
                });
                }
            }
        }
这个是ext的一段代码,file-uploadServlet到了这个servlet文件已经上传完毕了,但是我后台怎么告诉前台js我上传成功,让success=true执行括号内的语句并且waitMsg去除等待呢

解决方案 »

  1.   

    有个例子,自己看下吧
    Ext.namespace("testdomain");
    Ext.onReady(function(){
        Ext.BLANK_IMAGE_URL="../../img/s.gif";    
        var viewport = new Ext.Viewport({
            layout: 'border',
            items: [{
                
                region: 'center',
                tbar:[{
                    text:'测试',
                    handler:function(){
                    var file = new Ext.form.TextField({
                        fieldLabel: '流程信息',
                        labelStyle: 'width:60px',
                        anchor:'80%',
                        inputType: 'file'//文件类型
                    });        
                    var panelFile = new Ext.form.FormPanel({
                        labelAlign: 'right',
                        labelWidth: 60,
                        frame:true,
                        border:false,
                        fileUpload: true,
                        enctype:'multipart/form-data',
                        method:'POST',
                        width: 380,
                        items: [file],
                        buttons: [{
                            text: '确定',
                            handler: function() {
                                if(file.getValue()==""){
                                    Ext.MessageBox.alert('警告', "请选择需要导入的流程信息!");
                                    return;
                                }
    //                            var reg = /\.txt$|\.xml$/i;
    //                            if(file.getValue().match(reg)==null){
    //                                Ext.MessageBox.alert('警告', "请选择“txt”或者“xml”格式的文件!");
    //                                return;
    //                            }
                                win.hide();
                                
                                panelFile.getForm().submit({   
                                    url:'/TestWeb/TestAction.do?method=upload',
                                    params:{},
                                    success:function(form,action){ 
                                        Ext.MessageBox.alert("提示 ","success");
                                    },   
                                    failure:function(form,action){ 
                                        Ext.MessageBox.alert("警告","failure"); 
                                    }   
                                });
                            }
                        }]
                    });
                    var win=new Ext.Window({
                        title:'导入文件',
                        width:320,
                        height:160,
                        closable:true,
                        maximizable:true,
                        plain: false,
                        border:false,
                        modal:true,
                        items:[panelFile]
                    });
                    win.show();
                }
                }]
                
            }] 
        });    
    });
      

  2.   

    后台返回一个 {"success":true,"message":xxx}的json字符串 ext会执行 success的function