检测用户名可用

来源:互联网 发布:网络彩票概念股 编辑:程序博客网 时间:2024/05/15 23:51

<input id="Button1" type="button" value="检测用户名" />

 

 

 

 

 

 

 

<script type="text/javascript" language="javascript">
    $(document).ready(function(){
        //验证用户名
        $('#Button1').click(function(){
            var userName=$('#txtUserName').val();
            $.get('/Ajax/IsExistUser.ashx?uname='+userName,function(result){
              alert(result);
            });
        });
      });
    </script>

 

 

 

在一般处理文件中写这个

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace Ticket.Web.Ajax
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class IsExistUser : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {

 

        context.Response.Cache.SetNoStore();



            context.Response.ContentType = "text/plain";
            string userName = Ticket.Common.RequestFilter.GetQueryString("uname", true);
            context.Response.StatusCode = 200;
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            if (!string.IsNullOrEmpty(userName))
            {
                bool isPass = Ticket.Logic.Member.ExistsParam("username",userName,"tblMember");//写个方法判断是否有用
                if (!isPass)
                {
                    context.Response.Write(string.Format("恭喜您,用户名 {0} 可以使用!", userName));
                }
                else
                {
                    context.Response.Write(string.Format("用户名{0}已经被使用,请重新输入!", userName));
                }
            }
            else
            {
                context.Response.Write("请输入用户名!");
            }
        }

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