ajax检查用户名是否存在

您所在的位置:网站首页 ajax验证用户名是否存在 ajax检查用户名是否存在

ajax检查用户名是否存在

#ajax检查用户名是否存在| 来源: 网络整理| 查看: 265

腾讯云实验平台开春福利,100+门实验限免体验,精品实验享8折优惠! >>>

    检查用户名是否存在            var xmlHttp = null;

        function createXMLHttpRequest() {            if (xmlHttp == null) {                if (window.XMLHttpRequest) {                    //Mozilla 浏览器                    xmlHttp = new XMLHttpRequest();                } else if (window.ActiveXObject) {                    // IE浏览器                    try {                        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");                    } catch (e) {                        try {                            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");                        } catch (e) {                            //alert('创建失败');                        }                    }                }            }        }        function openAjax() {            if (xmlHttp == null) {                createXMLHttpRequest();                if (xmlHttp == null) {                    //alert('出错');                    return;                }            }

            var val = document.getElementById('txt').value;

            xmlHttp.open("get", "VerifyUserNameHandler.ashx?para=" + val + "&date=" + new Date(), true);            xmlHttp.onreadystatechange = xmlHttpChange;            xmlHttp.send(null);

            document.getElementById('resultSpan').innerText = '正在检查,请稍候...';        }

        function xmlHttpChange() {            if (xmlHttp.readyState == 4) {                if (xmlHttp.status == 200) {                    var res = xmlHttp.responseText;                    document.getElementById('resultSpan').innerText = res;

                    if (res == '恭喜,用户名可以使用。') {                        setTimeout("document.getElementById('resultSpan').innerText='';", 2000);                    }                    else if (res == '抱歉,用户名已被使用。') {                        document.getElementById('txt').focus();                    }                }            }        }                           用户名:               

 

using System;using System.Collections.Generic;using System.Linq;using System.Web;

namespace CheckUser{    ///     /// VerifyUserNameHandler 的摘要说明    ///     public class VerifyUserNameHandler : IHttpHandler    {

        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            //context.Response.Write("Hello World");            string _name = context.Request.QueryString["para"];            _name = string.IsNullOrEmpty(_name) ? "" : _name;            System.Threading.Thread.Sleep(500);//用线程来模拟数据库查询工作            string[] Names = new string[] { "pannian", "liupeng", "chenhao" };//这里用Names数组来代替数据库中的结果集            if (Array.IndexOf(Names, _name) == -1)            {                context.Response.Write("恭喜,用户名可以使用。");            }            else            {                context.Response.Write("抱歉,用户名已被使用。");            }        }

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

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3