<
html
>
html
>
<
head
>
<
title
>
AjaxTest
</
title
>
<
script
>
var
xmlHttp;
function
createXMLHttpRequest()
createXMLHttpRequest()
{
if
(window.ActiveXObject)
{
xmlHttp
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
}
else
if
(window.XMLHttpRequest)
{
xmlHttp
=
new
XMLHttpRequest();
}
}
function
startRequest()
startRequest()
{
createXMLHttpRequest();
try
{
{
var
username
=
document.getElementById(
"
<%=text1
.ClientID
%>"
).value;
xmlHttp.onreadystatechange
=
handleStateChange;
=
handleStateChange;
xmlHttp.open(
"
GET
"
,
"
validname.aspx?username=
"
+
username,
true
);
xmlHttp.send(
null
);
null
);
}
catch
(exception)
{
catch
(exception)
{
alert(
"
xmlHttp Fail
"
);
"
xmlHttp Fail
"
);
}
}
function
handleStateChange()
{
if
(xmlHttp.readyState
==
4
)
(xmlHttp.readyState
==
4
)
{
if
(xmlHttp.status
==
200
||
xmlHttp.status
==
0
)
{
var
param
=
xmlHttp.responseText;
document.getElementById(
"
msg
"
).innerHTML
=
param;
param
=
xmlHttp.responseText;
document.getElementById(
"
msg
"
).innerHTML
=
param;
}
}
}
</
script
>
script
>
</
head
>
<
body
>
body
>
<
div
>
div
>
<
input
type
="type"
id
="text1"
/><
span
id
="msg"
></
span
><
br
>
<
input
type
="button"
value
="Test"
onclick
="startRequest();"
/>
</
div
>
</
body
>
</
html
>
public
void
Page_Load()
void
Page_Load()
{
string
userName
=
Request.QueryString
["
username
"
];
userName
=
Request.QueryString
["
username
"
];
if
(iExists(userName))
(iExists(userName))
{
Response.Write(
"
用户名存在
"
);
Response.Write(
"
用户名存在
"
);
}
else
{
Response.Write(
"
用户名可用
"
);
"
用户名可用
"
);
}
Response.End();
Response.End();
}
public
bool
iExists(
string
username)
{.....}
bool
iExists(
string
username)
{.....}