jquery验证用户名是否存在
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="_111_Default3" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>连接数据库</title>
- <mce:script src="jquery-1[1].2.1.pack.js" mce_src="jquery-1[1].2.1.pack.js"></mce:script>
- <mce:script type="text/javascript"><!--
- $(function (){ //$(document).ready(function (){ 的简写
- //$('#save').click(function (){
- //var params=$('input').serialize(); //序列化表单的值,与prototype中的form.serialize()相同
- //$.ajax({
- //url:'Default4.aspx',
- //type:'post', //数据发送方式
- //dataType:'html', //接受数据格式
- //data:'text='+$("#name").val()+'&password='+$("#password").val()+'&date='+new Date(), //要传递的数据
- //success:update_page //回传函数(这里是函数名)
- //});
- //});
- //});
- $('#name').mouseout(function (){
- var params=$('input').serialize(); //序列化表单的值,与prototype中的form.serialize()相同
- $.ajax({
- url:'Default4.aspx',
- type:'post', //数据发送方式
- dataType:'html', //接受数据格式
- data:'text='+$("#name").val()+'&password='+$("#password").val()+'&date='+new Date(), //要传递的数据
- success:update_page //回传函数(这里是函数名)
- });
- });
- });
- function update_page (json) { //回传函数实体,参数为XMLhttpRequest.responseText
- $("#div").html(json);
- }
- // --></mce:script>
- </head>
- <body>
- <form id="form2">
- name:<input type="text" value="cssrain" id="name"><br>
- password: <input type="text" value="" id="password"><br>
- <input type="button" value="save" id="save">
- </form>
- <div id="div"></div>
- </body>
- </html>
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using dckj.BLL;
- using dckj.Models;
- public partial class _111_Default4 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //String text = Request.Form["text"];
- //String password = Request.Form["password"];
- //Users user = new Users();
- //user.Name = "admin";
- //user.Pwd = password;
- //user.Username = text;
- //if (UsersManager.login(text, password))
- //{
- // Response.Write("name= '" + text + "'; address= '" + password + "'; 用户名密码正确'");//设置返回值
- //}
- //else
- //{
- // Response.Write("name= '" + text + "'; address= '" + password + "'; 用户名密码不正确'");//设置返回值
- //}
- String text = Request.Form["text"];
- Users user = new Users();
- if (UsersManager.GetUserByName(text) == null)
- {
- Response.Write("name= '" + text + "' 用户名可以用'");
- }
- else
- {
- Response.Write("name= '" + text + "' 用户名已存在'");
- }
- }
- }