$("#login").click(function () { if ($('#userId').val() != "" && $('#pwdId').val() != "") { $.ajax({ type: 'Post', async: false, url: 'Login.aspx/loginYN', data: "{'username':'" + $('#userId').val() + "','password':'" + $('#pwdId').val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d == "1") { window.location.href = 'admin/index.aspx'; } else { alert("用户名或密码错误!"); } }, error: function (err) { alert("登录失败!请稍后再试或联系管理员。"); } }); } else { alert("请输入用户名或密码!"); } });
后台部分:
[WebMethod] public static string loginYN(string username, string password) { tb_admin lg = new tb_admin(); lg._username = username.Trim(); lg._password = FormsAuthentication.HashPasswordForStoringInConfigFile(password.Trim(), "MD5"); return b_login.loginYN(lg); }