前台页面:
function UserName() {
if ($("#hdnType").val() != "1") return; var str = $("#txtUid").val(); if (null != str && str.length > 0) { $.ajax( { type: "POST", url: "UserOp.aspx/NoExistUid", // UserOp.aspx为调用后台方法所在的画面(注意路径),NoExistUid为方法名称 data: "{uid: ' " + str + " '}", // uid为参数的名称,str为值;多个参数写法:"{'参数1':'值1','参数2':'值2',.....}" contentType: "application/json;charset=utf-8", dataType: "json", success: function (msg) { if (!msg.d) { $("#lblUserName").text("用户名已注册。"); } } }); } }
后台方法:
[WebMethod] //此方法必须标记为WebMethod public static bool NoExistEmail(string email) { if (Func.NotEmpty(email) && Func.IsEmail(email.Trim())) { int iResult = BllRegister.Instance.ExistEmail(email.Trim()); if (iResult <= 0) return false; } return true; }