• Ajax 判断数据库表中该用户是否存在


    index.html

    <script type="text/javascript">


            var xmlHttp;


            //创建XMLHttpRequest对象
            //目的:兼容浏览器
            function createXMLHttpRequest() {
                if (window.ActiveXObject) {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
                }
                else if (window.XMLHttpRequest) {
                    xmlHttp = new XMLHttpRequest();
                }
            }


            function StringBuilder() {

                var userName = document.getElementById("User").value;

                return encodeURI(encodeURI(userName)); //两次编码解决中文乱码问题
            }

       //当状态改变的时候

            function StateChange() {
                if (xmlHttp.readyState == 4 && xmlHttp.Status == 200) {
                    var responseDiv = document.getElementById("back");
                    responseDiv.innerHTML = decodeURI(xmlHttp.responseText); //解码
                }
            }

            //发送

            function SendToPage() {

                createXMLHttpRequest();

                var queryString = "Page_1.aspx?U=";
                queryString += StringBuilder();

                xmlHttp.open("GET", queryString);

                xmlHttp.onreadystatechange = StateChange;

                xmlHttp.send(null);
            }

    <body>
        用户名:<input type="text" name="UserName" id="User" />
        <input type="button" name="btn" value="Show" onclick="SendToPage();" /><br />
        <div id="back">
        </div>
    </body>

    IsExists.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
            {
                if (Request.QueryString["U"] != null)
                {
                    Session["User"] = Request.QueryString["U"].ToString();
                    Response.Write(Check());
                    Response.End();
                }
            }

            protected string Check()
            {
                string sql = string.Empty;
                string res = string.Empty;

                if (Session["User"] != null)
                {
                    sql = "select count(*) from T_Person where C_Name='" + Session["User"].ToString() + "'";
                }
                else
                {
                    res = "error";
                    return res;
                }

                if ((int)new SQLHelper().ExecuteScalar(sql) == 0)
                {
                    res = "不存在该用户名!";
                }
                else
                {
                    res = "已存在该用户名!";
                }
                return res;
            }


                    
        </script>

  • 相关阅读:
    经典的笔试题python操作数据库和python设计模式【多测师_王sir】
    上证所python笔试题【多测师_王sir】
    银行移动消费信贷业务梳理【多测师_王sir】
    查看log.txt 日志文件中包含关键字x123或者x124的行,以及该行前后10行内容,并输出到out.txt中【多测师_王sir】【Linux题目】
    文件权限设置
    windows OpenSSH WARNING: UNPROTECTED PRIVATE KEY FILE!
    vue对象合并
    elk安装配置
    ElasticSearch
    Elastic Search之Search API(Query DSL)、字段类查询、复合查询
  • 原文地址:https://www.cnblogs.com/meroselove/p/2212535.html
Copyright © 2020-2023  润新知