【200分】jquey ajax +asp.net 一般处理程序(ashx)
<head id="Head1" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>登录</title>
<link href="Content/login.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="jqueryui/css/smoothness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="Script/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var $username = $("#txt_username");
var $userpwd = $("#txt_userpwd");
var $logincode = $("#logincode");
var $info = $("#lbl_info");
var $remeberpwd = $(":checkbox[name='remeberpwd']").attr("checked") == true ? "1" : "0";
$("#btn_login").click(function () {
if (checkinput() == true) {
$.ajax({
type: "post",
url: "ajax/MyLoginHandler.ashx",
data: "{'username':'" + $username.val() + "','userpwd':'" + $userpwd.val() + "','remeberpwd':'" + $remeberpwd + "','logincode':'" + $logincode.val() + "'}",
success: function (msg) {
alert(1);
},
error: function () {
alert(2);
// showvalidatecode();
}
});
}
return false;
});
$("#getcode_img").click(function () {
showvalidatecode();
});
function showvalidatecode() {
$("#getcode_img").attr("src", "Control/validate.aspx");
};
function checkinput() {
if ($username.val().length == 0) {
$info.text("用户名为空");
return false;
}
if ($userpwd.val().length == 0) {
$info.text("密码为空");
return false;
}
//加上js正则
return true;
};
});
</script>
</head>
public class MyLoginHandler : IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
string username = context.Request.Form["username"];
string userpwd = context.Request.Form["userpwd"];
string remeberpwd =context.Request.Form["remeberpwd"];
string logincode = context.Request.Form["logincode"];
if (logincode == context.Session["logincodenum"].ToString())
{
if (new LoginHandler().ValidateUser(username, userpwd))
{
if (remeberpwd == "1")
{
}
context.Response.Write("3" + "|登陆成功,进行跳转");
}
else
{
context.Response.Write("2" + "|用户名或密码错误");
}
}
else
{
context.Response.Write("1" + "|验证码错误");
}
}
data: "{'username':'" + $username.val() + "','userpwd':'" + $userpwd.val() + "','remeberpwd':'" + $remeberpwd + "','logincode':'" + $logincode.val() + "'}",
data: "co="+$.trim(str.val())+"&wd="+$.trim(pwd.val())+"&kp="+keepPW+"&type=usual&way="+$("#hidtype").val()+"&acDate="+(new Date().getTime()),
}
看看弹出来的是什么错误
[解决办法]
$.post(url, $(#form1).serialize(), callback, datatype);
用post试试 不用拼写表单元素 直接提交表单...
看你这问题猜是 ajax data数据的问题
[解决办法]
data格式错了。
data:{"username":$username.val(),"userpwd":$userpwd.val(),"remeberpwd":$remeberpwd.val(),"logincode":$logincode.val()}
[解决办法]