现在的位置: 首页 > 综合 > 正文

Ajax调用后台方法

2013年10月22日 ⁄ 综合 ⁄ 共 1169字 ⁄ 字号 评论关闭

前台页面:

 

            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;
    }

抱歉!评论已关闭.