Ajax检测用户名是否存在
2009-05-22 14:19
357 查看
Ajax应用的一个简单的例子: <html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
<script language="javascript">
var http_request = false;
function send_request(url) //初始化、指定处理函数、发送请求的函数
{
http_request = false;//初始化XMLHttpRequest对象
if (window.ActiveXObject)
{ // IE浏览器
try
{
http_request = new XMLHttpRequest();
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}
if (!http_request)
{ // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, true);
http_request.send(null);
}
// 处理返回信息的函数
function processRequest()
{
if (http_request.readyState == 4)
{ // 判断对象状态
if (http_request.status == 200)
{ // 信息已经成功返回,开始处理信息
alert(http_request.responseText);
}
else
{ //页面不正常
alert("您请求的页面有异常。");
}
}
}
function userCheck()
{
var f = document.form1;
var username = f.username.value;
if(username=="")
{
window.alert("用户名不能为空。");
f.username.focus();
return false;
}
else
{
send_request("NameServer.aspx?username="+username);
}
}
</script> </head>
<body>
<form id="form1" runat="server" method="post">
<div>
用户名:<input type="text" name="username" value="" />
<input type="button" name="check" value="检查" onClick="userCheck()" /> </div>
</form>
</body>
</html> NameServer.aspx页面后台代码: string username = Request.QueryString["username"];
if (username == "1")
Response.Write("用户名已经被注册,请更换一个用户名。");
else
Response.Write("用户名尚未被使用,您可以继续。");
<head id="Head1" runat="server">
<title>无标题页</title>
<script language="javascript">
var http_request = false;
function send_request(url) //初始化、指定处理函数、发送请求的函数
{
http_request = false;//初始化XMLHttpRequest对象
if (window.ActiveXObject)
{ // IE浏览器
try
{
http_request = new XMLHttpRequest();
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
}
}
}
if (!http_request)
{ // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, true);
http_request.send(null);
}
// 处理返回信息的函数
function processRequest()
{
if (http_request.readyState == 4)
{ // 判断对象状态
if (http_request.status == 200)
{ // 信息已经成功返回,开始处理信息
alert(http_request.responseText);
}
else
{ //页面不正常
alert("您请求的页面有异常。");
}
}
}
function userCheck()
{
var f = document.form1;
var username = f.username.value;
if(username=="")
{
window.alert("用户名不能为空。");
f.username.focus();
return false;
}
else
{
send_request("NameServer.aspx?username="+username);
}
}
</script> </head>
<body>
<form id="form1" runat="server" method="post">
<div>
用户名:<input type="text" name="username" value="" />
<input type="button" name="check" value="检查" onClick="userCheck()" /> </div>
</form>
</body>
</html> NameServer.aspx页面后台代码: string username = Request.QueryString["username"];
if (username == "1")
Response.Write("用户名已经被注册,请更换一个用户名。");
else
Response.Write("用户名尚未被使用,您可以继续。");
相关文章推荐
- 毕业设计(十)---用DWR实现 代替AJAX 用户注册检测用户名是否已经存在
- Ajax简单应用,Ajax检测用户名是否存在
- 毕业设计(十)---用DWR实现 代替AJAX 用户注册检测用户名是否已经存在
- Ajax简单应用,检测用户名是否存在
- PHP+Ajax检测用户名或邮件注册时是否已经存在实例教程
- PHP+Ajax检测用户名或邮件注册时是否已经存在实例教程
- ajax 检测注册用户名是否存在
- jquery与php交互的ajax应用第一课:检测用户注册时用户名是否存在
- spring+jquery+ajax 检测用户名是否存在
- ajax检测用户名是否存在
- 应用ajax实现检测注册用户名是否已经存在
- 使用jquery+ajax方式实现用户注册时,检测用户名是否存在
- 利用ajax检测用户名是否存在
- JQuery+Ajax实现用户名的检测(用户名是否已存在)
- Ajax简单应用,检测用户名是否存在 (转)
- Ajax js 使用Ajax检测用户名是否存在
- 使用jquery+ajax方式实现用户注册时,检测用户名是否存在
- Ajax检测用户名是否存在
- jquery与php交互的ajax应用第一课:检测用户注册时用户名是否存在
- 使用Ajax实时检测"用户名、邮箱等"是否已经存在