代码改变世界

Ext数据提交

2010-01-15 14:28  smat  阅读(164)  评论(0编辑  收藏  举报

1, EXT的form表单ajax提交(默认提交方式)

function login(item) {
           
             if (validatorForm()) {
                 // 登录时将登录按钮设为disabled,防止重复提交
                 this.disabled = true;
 
                 // 第一个参数可以为submit和load
                 formPanl.form.doAction('submit', {
 
                      url : 'user.do?method=login',
  
                      method : 'post',
  
                      // 如果有表单以外的其它参数,可以加在这里。我这里暂时为空,也可以将下面这句省略
                          params : '',
  
                          // 第一个参数是传入该表单,第二个是Ext.form.Action对象用来取得服务器端传过来的json数据
                          success : function(form, action) {
  
                              Ext.Msg.alert('操作', action.result.data);
                              this.disabled = false;
  
                          },
                          failure : function(form, action) {
  
                              Ext.Msg.alert('警告', '用户名或密码错误!');
                              // 登录失败,将提交按钮重新设为可操作
                              this.disabled = false;
  
                          }
                      });
                  this.disabled = false;
              }
          }

2.EXT表单的非ajax提交

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

3.EXT的ajax提交

Ext.Ajax.request({
                                       //请求地址
                     url: 'login.do',
                     //提交参数组
                     params: {
                         LoginName:Ext.get('LoginName').dom.value,
                         LoginPassword:Ext.get('LoginPassword').dom.value
                      },
                      //成功时回调
                      success: function(response, options) {
                        //获取响应的json字符串
                        var responseArray = Ext.util.JSON.decode(response.responseText);                                              
                            if(responseArray.success==true){
                                Ext.Msg.alert('恭喜','您已成功登录!');    
                            }
                            else{
                                Ext.Msg.alert('失败','登录失败,请重新登录');    
                            }
                    }
            });