首页 新闻 搜索 专区 学院

asp.net 在无刷检测用户是否注册过,出现错误,各位大虾帮帮忙,小弟万分感谢

0
[待解决问题]

我在 无刷新检测用户是否注册过时总是出错,无效果。

我在注册页面的代码如下:

<script type="text/javascript" language="javascript">
                             function checkConfirm() {
                                 var Username = $("#txtM_user1").val();
                                 var url = "/Member/LoginNameExist.aspx";
                                 $.get(url, { UserName: Username }, function(data) {
                                     if (data == '1') {
                                         $("#NameExist").html("<font color=\"red\">该用户已被注册!</font>");
                                     }
                                     else {
                                         $("#NameExist").html("该用户可以使用!");
                                     }
                             })
                            </script>

控件:<li><p>用户名:</p>
                              <!--  <input id="txtM_user1" type="text" onblur="checkConfirm()" />-->
                                <asp:TextBox ID="txtM_user" runat="server" Width="130px" onblur="checkConfirm();"></asp:TextBox><font color="red">*</font>
                                <asp:RequiredFieldValidator ID="RFV_M_user" runat="server"
                                    ControlToValidate="txtM_user" ErrorMessage="用户名不能用空!"></asp:RequiredFieldValidator><div id="NameExist"></div>
                            </li>

在验证页面的LoginNameExist.aspx中只有一句代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginNameExist.aspx.cs" Inherits="AirBtc.Web.Member.LoginNameExist" %>

在LoginNameExist.aspx.cs中提供对数据库的访问,代码如下:

protected void Page_Load(object sender, EventArgs e)
        {
            //string reqName = Request.QueryString["UserName"];
            string reqName=Request["UserName"];
            LoginNameExist11(reqName);
        }
        public void LoginNameExist11(string reqname)
        {
            //string str="admin";//测试
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnString1"].ToString());//连接数据库

            try
            {
                conn.Open();
                string sql = "Select UserName From [Users] where UserName='" + reqname + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Response.Write("1");
                }
                else
                {
                    Response.Write("0");
                }

            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            finally {

                conn.Close();
            }

出现问题:当文本域失去焦点的时候 报错  -------------错误: “checkConfirm”未定义

怎么解决呀,各位大虾帮帮忙,小弟万分感谢!

道勤2016的主页 道勤2016 | 初学一级 | 园豆:30
提问于:2011-06-21 10:36
< >
分享
所有回答(2)
0

js中的括号不匹配了

荣冬 | 园豆:215 (菜鸟二级) | 2011-06-21 11:34
0

 在最后加个}

 function checkConfirm() {
                                 var Username = $("#txtM_user1").val();
                                 var url = "/Member/LoginNameExist.aspx";
                                 $.get(url, { UserName: Username }, function(data) {
                                     if (data == '1') {
                                         $("#NameExist").html("<font color=\"red\">该用户已被注册!</font>");
                                     }
                                     else {
                                         $("#NameExist").html("该用户可以使用!");
                                     }
                             })}
                            </script>

plccs | 园豆:250 (菜鸟二级) | 2011-06-21 15:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册