TEL:150-0382-3679
新闻资讯 News Center
建站知识 / 公司动态
.net验证用户是否注册(不刷新页面)

点击某一超链接调用javascript方法

<a href=“javascript:ajax();”>点击验证</a>

//ajax

<script language="javascript" type="text/javascript">

    var request = false;

    function ajax()

    {

        var error = true;

        try

        {

            request = new XMLHttpRequest();

        }

        catch (trymicrosoft)

        {

            try

            {

                request = new ActiveXObject("Msxml2.XMLHTTP");

            }

            catch (othermicrosoft)

            {

                try

                {

                     request = new ActiveXObject("Microsoft.XMLHTTP");

                }

                catch (failed)

                {

                    request = false;

               

            }

        }

        if(!error)

        {

            alert("ajax error!");

        }

        request.open("GET","validateEmail.aspx?session="+document.getElementByIdx("txtEmail").value,true);//验证的文本框名称

        request.onreadystatechange = updatePage;

        request.send(null);

    }

    function updatePage()

    {

        if(request.readyState == 4)

        {

            if(request.responseText=="1")

            {

                alert("该用户已经注册!");

                return false;

            }

            if(request.responseText=="0")

            {

                alert("可以注册!");

                return false;

            }

        }

    }

</script>

    单独一页,别的页调用它:validateEmail.aspx

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Request.QueryString["session"] != null)//验证页面传递过来的值

        {

            string session = Request.QueryString["session"].ToString();

            registerBll regb = new registerBll();

            DataSet ds = regb.selectMemberxx(session);//数据连接的查询类,以查询用户名

            if (ds.Tables[0].Rows.Count > 0)

            {

                Response.Write("1");

            }

            else

            {

                Response.Write("0");

            }

        }

    }

一站式全网营销,您身边的网络营销顾问,为您一对一私人定制符合您实际需求的网络营销实施方案!
24小时咨询热线:
150-0382-3679