EXTJS 资料 Ext.Ajax.request 获取返回数据

时间:2022-02-27 19:34:26
下面是一个登陆页面调用的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 = ;
DataSet ds = saBLL.Login(username, password); //客户端输出变量
string strResult = string.Empty;
if (ds.Tables[].Rows.Count > )
{
//用户不存在
if (ds == null)
strResult = "{success:true,flag:false,msg:'用户不存在!'}";
//用户密码不正确
else if (ds.Tables[].Rows[]["Password"].ToString() != password)
strResult = "{success:true,flag:false,msg:'用户密码不正确!'}";
//正确
else
{
intUserID = Convert.ToInt32(ds.Tables[].Rows[]["AccountId"].ToString());
strResult = "{success:'true',flag:'true',userid:'" + intUserID + "',username:'" + ds.Tables[].Rows[]["LoginName"] + "'}";
}
}
else
{
strResult = "{success:true,flag:false,msg:'用户不存在!'}";
} //客户端输出
context.Response.Write(strResult); }