extjs3.3 表单的提交
Extjs表单提交

第一种提交方式: Ext.Ajax.request
buttons:[{ text:'保存', handler:function(){ if(Ext.getCmp("train.code").getValue()!=""){ Ext.Ajax.request({ url:'trainAction!addTrain',//访问的action中的方法的url路径 method:'POST',//访问请求的方式 post,get params:{ //所要提交表单的数据 'train.code':Ext.getCmp("train.code").getValue(), 'train.name':Ext.getCmp("train.name").getValue(), 'train.entity':Ext.getCmp("train.entity").getValue(), 'train.industry':Ext.getCmp("train.industry").getValue(), 'train.status':Ext.getCmp("train.status").getValue(), 'train.corporat':Ext.getCmp("train.corporat").getValue(), 'train.manager':Ext.getCmp("train.manager").getValue(), 'train.sincedate':Ext.getCmp("train.sincedate").getValue(), 'train.yearrevenue':Ext.getCmp("train.yearrevenue").getValue(), 'train.addr01':Ext.getCmp("train.addr01").getValue() }, success:function(form, action) {//成功后执行 window.location.href="train/jsp/trainList.jsp"; }, failure:function() {//提交表单失败后执行 alert("添加失败"); } }) }else{ alert("添加失败"); } }]
采用第二种方式
//使用第二种方式:submit提交方式 form.getForm().submit( { url:'trainAction!addTrain', success: function(form, action) { alert(action.result.msg); window.location.href = "index.jsp"; }, failure: function(form, action) { Ext.Msg.alert("错误", action.result.msg); } } );
第三种提交方式(类似第一种方式只不过把params配置去掉换成form)
items:[ { text:'保存', iconCls:'save', handler:function(){ Ext.Ajax.request({ url:'trainAction!updateTrain', method:'POST', form: formEidt.getForm().id,//直接找到form然后把form中的整个内容提交上去 success:function(form, action) { window.location.href="train/jsp/trainList.jsp"; }, failure:function() { alert("修改失败1"); } }) } } ]
服务器端action代码
private Map<String,Object> datas= new HashMap<String,Object>(); public String addTrain() throws Exception{ trainService.add(train); datas.put("ok", "ok"); return "json"; }
struts2.xml中的代码
<package name="default" namespace="/" extends="json-default"> <action name="trainAction" class="trainAction"> <result name="json" type="json"> <param name="root">datas</param> </result> </action> </package>
浙公网安备 33010602011771号