首页 > 其他 > 详细

Ajax验证用户是否存在

时间:2014-02-21 18:51:57      阅读:278      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="regdemo.aspx.cs" Inherits="regdemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript">
        function loadXMLDoc() {
            var xmlhttp;
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function ()
            {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                {
                    document.getElementById("myuser").innerHTML = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET", "./ajax/checkuser.aspx?username="+ document.getElementById(Text1).value +"", true);
            xmlhttp.send(null);
        }
    </script>        
</head>
<body>
    <form id="form1" runat="server">
    <div>
        用户:
        <input id="Text1" type="text" onchange ="loadXMLDoc()" /><label id="myuser" style="color:red;"></label><br />
        <br />
        密码:
        <input id="Text2" type="text" />                 
    </div>
    </form>
</body>
</html>
bubuko.com,布布扣

 

bubuko.com,布布扣
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CnxinwaDll;

public partial class ajax_checkuser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request["username"].ToString() == "") {
            Response.Write("用户名不能为空");
            Response.Flush();
            Response.End();
        }
        else if (isexit(Request["username"].ToString()))
        {
            Response.Write("用户名存在,不可以注册:" + Request["username"].ToString());
            Response.Flush();
            Response.End();
        }
        else if (!isexit(Request["username"].ToString()))
        {
            Response.Write("用户名不存在,可以注册:" + Request["username"].ToString());
            Response.Flush();
            Response.End();
        }

    }
    /// <summary>
    /// 验证用户账号是否存在,存在返回TRUE否则返回FALSE
    /// </summary>
    /// <param name="uname"></param>
    /// <returns></returns>
    protected Boolean isexit(string uname) {
        Data.sqlstr = "select c003 from cnxinwa002 where c002=‘" + uname + "";
        if (Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count > 0)
        {
            return true;
        }
        else
        {
            return false;
        }       
    }
}
bubuko.com,布布扣

Ajax验证用户是否存在

原文:http://www.cnblogs.com/cnxinwa/p/3558874.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!