1.判断当前用户是否存在
HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="JqueryAjax_Default" %>
<!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>
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#submit").click(function () {
var name = $("#name").val();
var data = 'userName=' + name;
$.ajax({
type: "GET",
url: "Default.aspx",
data: data,
success: function (Msg) {
$('#message').html(Msg).css({ 'color': 'red' });
}
});
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>Please Enter Your Name</label>
<input type="text" id="name" /><br />
<input type="button" id="submit" value="Submit" />
</div>
<div id="message">
</div>
</form>
</body>
</html>
c#
protected void Page_Load(object sender, EventArgs e)
{
List<string> ListName = new List<string>();
ListName.Add("huguo");
ListName.Add("guo");
ListName.Add("ws_hgo");
if (Request.QueryString.Count != 0)
{
string name = Request.QueryString["userName"].ToString();
if (ListName.Contains(name))
{
Response.Write("用户验证成功!");
}
else
{
Response.Write("当前用户不存在!");
}
Response.End();
}
}