Ajax简单应用,检测用户名是否存在
2007-06-12 19:59
756 查看
客户端页面index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "' target=_blank>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ajax测试</title>
<script language="javascript" type="text/javascript">
//生成Http请求对象,用于客户端向服务/端发送异步的http请求
function getHttpObject()
{
var http;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
//如果用户使用IE,就返回XMLHTTP的ActiveX对象
http = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
else
{
//否则返回一个XMLHttpRequest对象
http = new XMLHttpRequest();
}
return http;
}
//获取全局的HTTP请求对象
var http = getHttpObject();
//处理请求状态变化
function getHello()
{
//4表示请求已完成
if (http.readyState == 4)
{
//获取服务段的响应文本
var helloStr = http.responseText;
alert(helloStr);
if(helloStr.charAt(0)!="0")
{alert("用户名已经存在!");}
else
{alert("用户名不存在,可以实用!");}
}
}
function HelloWorld()
{
var url = "Check.aspx?id="+document.getElementById("Text1").value;
//指定服务端的地址
http.open("GET", url, true);
//请求状态变化时的处理函数
http.onreadystatechange = getHello;
//发送请求
http.send(null);
}
</script>
</head>
<body>
<input id="Text1" style="width: 116px" type="text" />
<input id="Button1" type="button" value="button" onclick="javascript:HelloWorld();" />
</body>
</html>
服务器端功能页面Check.aspx
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Check : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "select Count(*) from Table where Name=" + Request.QueryString["id"].ToString() + "";
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Database;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand(str, conn);
int i = (int)cmd.ExecuteScalar();
conn.Close();
Response.Write(i);
}
}
转自:RelaxMyself 释放的天空
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "' target=_blank>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ajax测试</title>
<script language="javascript" type="text/javascript">
//生成Http请求对象,用于客户端向服务/端发送异步的http请求
function getHttpObject()
{
var http;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
//如果用户使用IE,就返回XMLHTTP的ActiveX对象
http = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
else
{
//否则返回一个XMLHttpRequest对象
http = new XMLHttpRequest();
}
return http;
}
//获取全局的HTTP请求对象
var http = getHttpObject();
//处理请求状态变化
function getHello()
{
//4表示请求已完成
if (http.readyState == 4)
{
//获取服务段的响应文本
var helloStr = http.responseText;
alert(helloStr);
if(helloStr.charAt(0)!="0")
{alert("用户名已经存在!");}
else
{alert("用户名不存在,可以实用!");}
}
}
function HelloWorld()
{
var url = "Check.aspx?id="+document.getElementById("Text1").value;
//指定服务端的地址
http.open("GET", url, true);
//请求状态变化时的处理函数
http.onreadystatechange = getHello;
//发送请求
http.send(null);
}
</script>
</head>
<body>
<input id="Text1" style="width: 116px" type="text" />
<input id="Button1" type="button" value="button" onclick="javascript:HelloWorld();" />
</body>
</html>
服务器端功能页面Check.aspx
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Check : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "select Count(*) from Table where Name=" + Request.QueryString["id"].ToString() + "";
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Database;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand(str, conn);
int i = (int)cmd.ExecuteScalar();
conn.Close();
Response.Write(i);
}
}
转自:RelaxMyself 释放的天空
相关文章推荐
- Ajax简单应用,检测用户名是否存在 (转)
- Ajax简单应用,检测用户名是否存在
- Ajax简单应用,Ajax检测用户名是否存在
- jquery与php交互的ajax应用第一课:检测用户注册时用户名是否存在
- 应用ajax实现检测注册用户名是否已经存在
- 注册页中检测用户是否存在(简单的JQ版Ajax应用)
- jquery与php交互的ajax应用第一课:检测用户注册时用户名是否存在
- jquery与php交互的ajax应用第一课:检测用户注册时用户名是否存在
- AJAX 检测用户名是否存在
- 毕业设计(十)---用DWR实现 代替AJAX 用户注册检测用户名是否已经存在
- 使用jquery+ajax方式实现用户注册时,检测用户名是否存在
- AJAX简单示例——实现检测用户名是否可用
- 使用Ajax实时检测"用户名、邮箱等"是否已经存在
- PHP+Ajax检测用户名或邮件注册时是否已经存在实例教程
- ajax简单校验用户名是否存在
- ajax检测用户名是否存在
- JQuery+AJAX异步刷新的一个基础应用(检验用户名是否已存在)
- AJAX应用实例之检测用户名是否唯一(实例代码)
- AJAX应用--基于HTML,以GET或POST方式,检查注册用户名是否存在
- 使用jquery+ajax方式实现用户注册时,检测用户名是否存在