下面是一个登陆页面调用的EXTJS
login function,通过 url: '/UI/HttpHandlerData/Login/Login.ashx',获取返回登陆账户和密码!
Ext.onReady(function () { login = function (target) { if (eval(document.getElementById('TxtUserName')).value == "") { alert("提示! 请输入账户!"); return false; } else if (eval(document.getElementById('TxtPassword')).value == "") { alert("提示!请输入密码!"); return false; } else { var username = eval(document.getElementById('TxtUserName')).value; var password = eval(document.getElementById('TxtPassword')).value; Ext.Ajax.request({ url: '/UI/HttpHandlerData/Login/Login.ashx', method: 'POST', clientValidation: true, waitMsg: '正在提交数据...', waitTitle: '提示', params: { username: username, password: password }, success: function (response) { var data = Ext.decode(response.responseText); //设置Cookie new Extjs.cookie.set(data.userid, data.username); window.location.href = "../Page/InformationManagement/Index.html"; }, failure: function () { Ext.Msg.alert("提示", "登陆失败,请与管理员联系!"); } }); } } });
后台代码:
这是在一般处理程序中的代码:
public void ProcessRequest(HttpContext context) { string username = context.Request.Form["username"]; string password = context.Request.Form["password"]; int intUserID = 0; DataSet ds = saBLL.Login(username, password); //客户端输出变量 string strResult = string.Empty; if (ds.Tables[0].Rows.Count > 0) { //用户不存在 if (ds == null) strResult = "{success:true,flag:false,msg:'用户不存在!'}"; //用户密码不正确 else if (ds.Tables[0].Rows[0]["Password"].ToString() != password) strResult = "{success:true,flag:false,msg:'用户密码不正确!'}"; //正确 else { intUserID = Convert.ToInt32(ds.Tables[0].Rows[0]["AccountId"].ToString()); strResult = "{success:'true',flag:'true',userid:'" + intUserID + "',username:'" + ds.Tables[0].Rows[0]["LoginName"] + "'}"; } } else { strResult = "{success:true,flag:false,msg:'用户不存在!'}"; } //客户端输出 context.Response.Write(strResult); }