转自 :http://www.jb51.cc/article/p-nbteldrc-dp.html
- /**
- *<p>
- *第一种Ajax提交方式
- *</p>
- *<p>
- *这种方式需要直接使用extAjax方法进行提交
- *</p>
- *使用这种方式,需要将待传递的参数进行封装
- *
- *@return
- */
- functionsaveUser_ajaxSubmit1(){
- Ext.Ajax.request({
- url:'user_save.action',
- method:'post',
- params:{
- userName:document.getElementById('userName').value,248)"> password:document.getElementById('password').value
- },248)"> success:function(response,options){
- varo=Ext.util.JSON.decode(response.responseText);
- alert(o.msg);
- failure:function(){
- }
- });
- /**
- *第二种Ajax提交方式
- *这种方式将为ext的ajax指定一个html表单
- *使用这种方式,不需要将待传递的参数进行封装
- *
- *@return
- */
- functionsaveUser_ajaxSubmit2(){
- Ext.Ajax.request({
- url:'user_save.action',248)"> method:'post',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> form:'userForm',//指定表单///
- *第三种Ajax提交方式
- *这种方式将为ext的自己的表单进行提交
- *使用这种方式,需要使用ext自己的textField组件
- functionsaveUser_ajaxSubmit3(){
- //定义表单
- varformPanel=newExt.FormPanel({
- labelWidth:75,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> frame:true,248)"> bodyStyle:'padding:5px5px0',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> width:350,248)"> defaults:{
- 230
- },108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> defaultType:'textfield',248)"> items:[{
- fieldLabel:'用户名',248)"> name:'userName',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> allowBlank:false
- fieldLabel:'密码',248)"> name:'password'
- }] @H_301_292@ //定义窗口
- varwin=newExt.Window({
- title:'添加用户',248)"> layout:'fit',0); background-color:inherit">500,248)"> height:300,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> closeAction:'close',248)"> closable:false,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> plain: items:formPanel,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> buttons:[{
- text:'确定',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> handler:function(){
- varform=formPanel.getForm();
- varuserName=form.findField('userName').getValue().trim();
- varpassword=form.findField('password').getValue().trim();
- if(!userName){
- alert('用户名不能为空');
- return;
- }
- if(!password){
- alert('密码不能为空');
- form.submit({
- waitTitle:'请稍后...',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> waitMsg:'正在保存用户信息,请稍后...',248)"> success:function(form,action){
- alert(action.result.msg); @H_301_292@ failure:function(form,action){
- alert(action.result.msg);
- text:'取消',248)"> handler:function(){
- win.close(); @H_301_292@ win.show();
- /**
- *第四种Ajax提交方式
- *这种方式将html的表单转化为ext的表单进行异步提交
- *使用这种方式,需要定义好html的表单
- functionsaveUser_ajaxSubmit4(){
- newExt.form.BasicForm('userForm').submit({ @H_301_292@ }
第二种方式 ,实际使用中的例子
Ext.Ajax.request( { url : '/systemFile.do?method=addFileForJsp&type=fujian&tid='+ id,method : 'post',form : document.forms[0],// 指定表单 success : function(response,options) { fujianlist(id) ; top.Ext.exmsg("提示","<font color=green>附件添加成功!</font>"); },failure : function(form,action) { top.Ext.exmsg("提示","<font color=red>附件上传失败!</font>"); } });