一般处理文件的使用

在脚本中要执行一个后台的方法适合我们就用一般处理文件

例如:注册检测用户名是否可用

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        //验证用户名
        $('#txtuserName').change(function() {
            var UserName = document.getElementById("txtuserName").value;
            $.get("/Ajax/IsExistUser.ashx", { uname: UserName }, function(result) {
                if (result == "用户名" + UserName + "已经被使用,请重新输入!") {
                    $("#txtuserName").css({ border: "1px solid red" });
                    document.getElementById("spanUserName").innerHTML = "用户名" + UserName + "已经被使用,请重新输入!";
                    $("#txtuserName").focus();
                }
                else if (UserName.length > 4) {
                    if (result == "恭喜您,用户名 " + UserName + " 可以使用!") {
                        $("#txtuserName").css({ border: "1px solid #c4d2db" });
                        document.getElementById("spanUserName").innerHTML = "恭喜您,用户名 " + UserName + " 可以使用!";
                        $("#spanUserName").css({ color: "#666699" });
                    }
                }
            });
        });
    });
</script>

 

IsExistUser.ashx文件内容为:

   context.Response.ContentType = "text/plain";
                Entity.MemberInfo model = new Ticket.Entity.MemberInfo();
                string UserName = Common.Request.GetString("uname", true);
                model.UserName = UserName;
                context.Response.StatusCode = 200;
                context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                model = Logic.MemberLogic.GetModel(model, out errMsg);
                if (!string.IsNullOrEmpty(UserName))
                {
                    if (model == null)
                    {
                        if (UserName == "-1")
                        {
                            context.Response.Write("请勿输入非法字符");
                        }
                        else
                        {
                            context.Response.Write(string.Format("恭喜您,用户名 {0} 可以使用!", UserName));
                        }
                    }

}

 

 

 

例子2:点击标题 新的层中出来相应的内容

 //公告显示与隐藏DIV
        function doNotice(obj) {
            var divNTC = document.getElementById("divNotice");
            if (divNTC.style.display == "none") {
                divNTC.style.display = "";
                spanNoticeTitle.innerHTML = obj.innerHTML;
                $.ajax({
                    type: "post",
                    url: "/Ajax/NoticeHandler.ashx",
                    data: "id=" + obj.title,
                    success: function(msg) {
                        $("#spanNoticeContext").html("<p style='text-align:left;margin:5px 5px 5px 5px;'>&nbsp;" + msg + "</p>");
                    }
                });
            } else {
                divNTC.style.display = "none";
            }
        }

 

   <a href="#" οnmοusedοwn="doNotice(this)" title='<%#Eval("PeopleId")%>'>
                                        <%#Eval("Title")%></a>

 

 public void ProcessRequest(HttpContext context)
        {
            int errMsg = -1;
            JinRi.Ticket.Entity.NoticeInfo notice = new JinRi.Ticket.Entity.NoticeInfo();
            string id = JinRi.Ticket.Common.Request.GetString("id");
            if (!string.IsNullOrEmpty(id))
            {
                notice.PeopleId = Convert.ToInt32(id);
                notice = JinRi.Ticket.Logic.NoticeLogic.GetModel(notice, out errMsg);

            }
            if (errMsg != -1)
            {
                context.Response.Write(errMsg);
            }
            else
            {
                context.Response.Write(notice.Context);
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值