`
anson_xu
  • 浏览: 504838 次
  • 性别: Icon_minigender_1
  • 来自: 惠州
社区版块
存档分类

firebug调试Ext登录框

    博客分类:
  • Ext
阅读更多
今天照着例子用firebug调试了一个ext的登录(firebug调试需Ext包的支持)
1.js
Ext.onReady(function(){
    Ext.QuickTips.init();

// Create a variable to hold our EXT Form Panel.
// Assign various config options as seen.
    var login = new Ext.FormPanel({
        labelWidth:80,
        url:'login.asp',
        frame:true,
        title:'Please Login',
        defaultType:'textfield',
monitorValid:true,
// Specific attributes for the text fields for username / password.
// The "name" attribute defines the name of variables sent to the server.
        items:[{
                fieldLabel:'Username',
                name:'loginUsername',
                allowBlank:false
            },{
                fieldLabel:'Password',
                name:'loginPassword',
                inputType:'password',
                allowBlank:false
            }],

// All the magic happens after the user clicks the button    
        buttons:[{
                text:'Login',
                formBind: true,
                // Function that fires when user clicks the button
                handler:function(){
                    login.getForm().submit({
                        method:'POST',
                        waitTitle:'Connecting',
                        waitMsg:'Sending data...',

// Functions that fire (success or failure) when the server responds.
// The one that executes is determined by the
// response that comes from login.asp as seen below. The server would
// actually respond with valid JSON,
// something like: response.write "{ success: true}" or
// response.write "{ success: false, errors: { reason: 'Login failed. Try again.' }}"
// depending on the logic contained within your server script.
// If a success occurs, the user is notified with an alert messagebox,
// and when they click "OK", they are redirected to whatever page
// you define as redirect.

                        success:function(){
                        Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
   if (btn == 'ok'){
                        var redirect = 'test.asp';
                        window.location = redirect;
                                   }
        });
                        },

// Failure function, see comment above re: success and failure.
// You can see here, if login fails, it throws a messagebox
// at the user telling him / her as much. 

                        failure:function(form, action){
                            if(action.failureType == 'server'){
                                obj = Ext.util.JSON.decode(action.response.responseText);
                                Ext.Msg.alert('Login Failed!', obj.errors.reason);
                            }else{
                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText);
                            }
                            login.getForm().reset();
                        }
                    });
                }
            }]
    });


// This just creates a window to wrap the login form.
// The login object is passed to the items collection.      
    var win = new Ext.Window({
        layout:'fit',
        width:300,
        height:150,
        closable: false,
        resizable: false,
        plain: true,
        border: false,
        items: [login]
});
win.show();
});

2.处理页面testlogin.php(当然可以是action,servlet,jsp页面)
<?php
$loginUsername = isset($_POST["loginUsername"]) ? $_POST["loginUsername"] : "";

if($loginUsername == "f"){
    echo "{success: true}";
} else {
    echo "{success: false, errors: { reason: 'Login failed. Try again.' }}";
}
?>

3.效果如图
  • 大小: 130.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics