标签:
w3School里面的ajax方法很好,简写不容易出错,又比较直观。
js:
$.post("../ajax/Login.ashx",
{
UserName: username,
Pwd: pwd,
CheckCode: chkcode
},
function (data, status) {
if (data == "验证码不正确") {
alert("验证码不正确!");
}else if (data=="登录成功") {
alert("登录成功!");
}else {
alert("用户名或密码错误!");
}
});
后台ashx:
string username = context.Request.Form["UserName"].ToString();
string pwd = context.Request.Form["Pwd"].ToString();
string cm = context.Session["CheckCode"].ToString();
.....
using (cmd = new SqlCommand(strsql, con))
{
using (read = cmd.ExecuteReader())
{
if (!flag)
{
context.Response.Write("验证码不正确");
//drow.Add("验证码", "验证码不正确!");
//return;
}
else if (read.Read())
{
context.Response.Write("登录成功");
//drow.Add("登录成功", "登录成功!");
}
else
{
context.Response.Write("用户名或密码错误");
//drow.Add("登录失败", "用户名或密码错误!");
}
}
}
标签:
原文地址:http://www.cnblogs.com/500k/p/4677231.html