EXT JS 表单

来源:互联网 发布:python运行 编辑:程序博客网 时间:2024/05/16 15:17

先来一个简单的表单文件上传:

var fm = new Ext.FormPanel({autoScroll:true,applyTo: 'form',height: 215,width: 480,frame:false,fileUpload: true, //上传文件defaultType:'textfield',labelWidth:120,        //在formPanel面板上添加组件        items:[{xtype:'field',fieldLabel:'请选择要上传的文件 ',width:300,allowBlank:false,inputType:'file',name:'file'}]});

使用按钮来触发上传事件:

//EXT的默认form表单提交(ajax)

function upload() {     //第一个参数可以为submit或load     fm.form.doAction("submit",{         url : 'upload.action?t=' + new Date(),         //如果有表单以外的参数,则使用params:         waitTitle : '提示',         method : 'POST',         waitMsg : '正在上传,请稍候...',         success : function(form, action) { // 回调函数有2个参数,第一个是传入该表单,第二个是从服务器传回来的JSON             Ext.MessageBox.alert('提示', '上传成功');         },         failure : function(form, action) {             Ext.MessageBox.alert('提示', '上传失败');         }        });     }

EXT的ajax请求:

 Ext.Ajax.request({url: 'upload.do?t=' + new Date(),method: 'post',//处理ajax的返回数据success: function(response, options){status = response.responseText;var obj = Ext.util.JSON.decode(response.responseText);if(obj.success!=false){if(obj.finished){}else{}}},failure: function(){Ext.Msg.alert('错误', '发生错误了。');} });


 

原创粉丝点击