loner_li JQuery+AJax 实现简单的用户注册

web服务文件代码

 [WebMethod]
        public int ExecuteInsert(string name,string password)
        {
            string constr = ConfigurationManager.ConnectionStrings["SqlAjaxReg"].ConnectionString;
           
          
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandText = "insert into  T_User(UserName,PassWord)values(@name,@pwd) ";
            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@pwd", password);
           
          
            return cmd.ExecuteNonQuery();
        }
   
显示页

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="js/Jquery1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#btnReg').click(function () {
             
                $.ajax({
                    type: "post",
                    contentType: "application/json",
                    url: "WebService1.asmx/ExecuteInsert",
                    data: "{name:'" + $('#txtUserName').val() + "',password:'" + $('#txtPassword').val() + "'}",
                    success: function (result) {
                        alert("成功注册" + result.d + "条数据。");
                    }
                }
                );
            });
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        用户名:<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
        密码 :&nbsp;
        <asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
        <br />
        <br />
      
        <input id="btnReg" type="button" value="注册" />
    </div>
    </form>
</body>
</html>

web.config文件
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>
    <add name="SqlAjaxReg" connectionString="Data Source=.;Initial Catalog=School;User ID=xx;Password=xxxx;"/>
  </connectionStrings>
</configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值