日期:2014-05-16 浏览次数:20672 次
[WebMethod] public static string cp(string yp, string np) { object obj = System.Web.HttpContext.Current.Session["username"]; string username = ""; if (obj != null) username = obj.ToString(); StringBuilder strSql = new StringBuilder(); strSql.Append("select * from Users where UserName = @UserName"); OleDbParameter[] parameter = { new OleDbParameter("@UserName", OleDbType.VarChar,20)}; parameter[0].Value = username; OleDbDataReader dr = SqlHelper.GetRead(strSql.ToString(), parameter); if (dr.Read()) { string userpwd = dr["UserPwd"].ToString(); dr.Close(); if (yp == userpwd) { StringBuilder strSql2 = new StringBuilder(); strSql2.Append("update Users set UserPwd = @UserPwd where UserName = @UserName"); OleDbParameter[] parameter2 = { new OleDbParameter("@UserPwd", OleDbType.VarChar,32), new OleDbParameter("@UserName", OleDbType.VarChar,20)}; parameter2[0].Value = np; parameter2[1].Value = username; int rows = SqlHelper.ExecuteSql(strSql2.ToString(), parameter2); if (rows > 0) return "200"; else return "400"; } else return "400"; } else { dr.Close(); return "201"; } }
$("#csu").click(function () { if ($("#np").val() == $("#np2").val()) { $("#csu").attr("disabled", "disabled"); $.ajax({ type: "post", url: "Sys_Main.aspx/cp", data: "{'yp':'" + $("#yp").val() + "','np':'" + $("#np").val() + "'}", dataType: "json", contentType: "application/json; charset=utf-8", success: function (data) { var obj = jQuery.parseJSON(data) switch (data.d) { case "200": $("#info").text("密码更改成功!"); $("#yp").val(""); $("#np").val(""); $("#np2").val(""); break; case "400": $("#info").text("密码更改失败!"); break; } $("#csu").removeAttr("disabled"); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("错误:" + errorThrown); } }); } else $("#info").text("两次密码输入不一样!"); return false; });