牛腩购物11:完善用户注册 onblur 失去焦点 jquery ajax post方式使用 一般处理程序 判断用户是否存在 前台js的应用

前台js如下

 function checkuser(username) {
            var name = $.trim(username);

            if (name.length == 0) {
                $("#mes_Username").html("<img src='images/wrong.jpg'>用户名不可用,请重新更换用户名");
            }
            else {
                //开始 ajax 检测用户名
                var url = "handle/checkusername.ashx";
                $.post(url, { name: name }, function (data) {
                    if (data == "用户名存在") {
                        $("#mes_Username").html("<img src='images/wrong.jpg'>用户名已经存在,请重新更换用户名");
                        return false;
                    }
                    else if(data == "可以使用") {
                        $("#mes_Username").html("<img src='images/right.jpg'> ");
                    }
                    else
                    {
                        $("#mes_Username").html("<img src='images/wrong.jpg'>用户名不可用,请重新更换用户名");
                    }

                });

            }

        }
在asp.net 控件上,要注意.例如我们在 textbox控件上写 onblur 但是vs2010是不提示的,这是因为vs对于控件只提示 c#的代码(例如 onclick),但是
我们写onblur (失去焦点) 这个方法,他实际是可以执行的
 <asp:TextBox  runat="server" onblur="checkuser(this.value)"></asp:TextBox>
在一般处理程序的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Niunan.Shop.Web.handle
{
    /// <summary>
    /// checkusername 的摘要说明
    /// </summary>
    public class checkusername : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
           context.Response.ContentType = "text/plain";   //这里好像可以注释起来  
            
            string username = context.Request.Form["name"];
            if (!string.IsNullOrEmpty(username))
            {
                bool b=new Niunan.Shop.DAL.UserDAO().Exists(username);
                if (b)
                {
                    context.Response.Write("用户名存在");
                }
                else
                {
                    context.Response.Write("可以使用");
                }
            }
            else
            {
                context.Response.Write("用户名输入错误");
            }

           
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}