softfire 发表于 2013-1-29 12:54:27

三种Ext提交数据的方法

转自:http://www.17ext.com/showtopic-55.aspx

1, EXT的form表单ajax提交(默认提交方式)
1.function login(item) {   2.             3.            if (validatorForm()) {   4.                // 登录时将登录按钮设为disabled,防止重复提交   5.                this.disabled = true;   6.   7.                // 第一个参数可以为submit和load   8.                formPanl.form.doAction('submit', {   9.   10.                  url : 'user.do?method=login',   11.   12.                  method : 'post',   13.   14.                  // 如果有表单以外的其它参数,可以加在这里。我这里暂时为空,也可以将下面这句省略   15.                        params : '',   16.   17.                        // 第一个参数是传入该表单,第二个是Ext.form.Action对象用来取得服务器端传过来的json数据   18.                        success : function(form, action) {   19.   20.                            Ext.Msg.alert('操作', action.result.data);   21.                            this.disabled = false;   22.   23.                        },   24.                        failure : function(form, action) {   25.   26.                            Ext.Msg.alert('警告', '用户名或密码错误!');   27.                            // 登录失败,将提交按钮重新设为可操作   28.                            this.disabled = false;   29.   30.                        }   31.                  });   32.                this.disabled = false;   33.            }   34.      }

2.EXT表单的非ajax提交
1. //实现非AJAX提交表单一定要加下面的两行! onSubmit : Ext.emptyFn, submit : function() {   2. //再次设定action的地址   3. this.getEl().dom.action ='user.do?method=login'; this.getEl().dom.method = 'post';   4. //提交submit   5.this.getEl().dom.submit();   6. },

3.EXT的ajax提交
1.   2.   3. Ext.Ajax.request({   4.                                        //请求地址   5.                      url: 'login.do',   6.                      //提交参数组   7.                      params: {   8.                        LoginName:Ext.get('LoginName').dom.value,   9.                        LoginPassword:Ext.get('LoginPassword').dom.value   10.                      },   11.                      //成功时回调   12.                      success: function(response, options) {   13.                        //获取响应的json字符串   14.                        var responseArray = Ext.util.JSON.decode(response.responseText);                                                 15.                            if(responseArray.success==true){   16.                              Ext.Msg.alert('恭喜','您已成功登录!');       17.                            }   18.                            else{   19.                              Ext.Msg.alert('失败','登录失败,请重新登录');       20.                            }   21.                  }   22.            });
页: [1]
查看完整版本: 三种Ext提交数据的方法