笔记,记录一下ext的ajax
下面是一个登陆页面调用的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("提示", "登陆失败,请与管理员联系!");
}
});
}
}
});
java后台
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);
}
后记
ext自带的不能满足我的需求
最后还是,选择使用 jquery的ajax
var path = GC_DocumentRoot+'/proxy/json/ChanFrame/getFrame/';
$.ajax({
url:path,
dataType: "json",
type:'POST',
data : dataStr,
success : function(data) {
if (!Ext.isEmpty(data.Error)) {
var errorCode = data.Error.Code;
Ext.toast('服务获取数据异常!' + errorCode +':'+ data.Error.Message);
}
if (!Ext.isEmpty(data.Result)) {
var dataSet = data.Result.Frames;
Ext.getCmp('messageGridPanel').getStore().loadData(dataSet);
}
},
error : function(e) {
Ext.toast('异常!状态码:'+ e.status);
}
});