Ajax应用简单示例
2007-07-12 11:04
441 查看
<script language="JavaScript" type="text/javascript">
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
}
function checkUser(userId){
try{
var userObj = document.getElementById(userId);
var url = "test.asp?username=" +escape(userObj.value);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = checkUserOk;
xmlHttp.send(null);
}catch(exception){}
}
function checkUserOk(){
if (xmlHttp.readyState == 4) {
try{
var response = xmlHttp.responseText;
var alertObj = document.getElementById("reg_alert");
alertObj.innerHTML=response;
}catch(exception){}
}
}
</script>
<form name="form1" action="" method="post">
City<input type="text" name="username" id="username" size="25" >
<input type="button" name="check" value="检查唯一性" onClick=" checkUser('username')">
<span id="reg_alert" class="red_txt"> </span>
</form>
test.asp
<%
Response.ContentType = "text/html"
Response.Charset = "GB2312"
username=trim(request("username"))
if username="aaa" then
response.Write("ok")
else
response.Write("false")
end if
%>
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
}
function checkUser(userId){
try{
var userObj = document.getElementById(userId);
var url = "test.asp?username=" +escape(userObj.value);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = checkUserOk;
xmlHttp.send(null);
}catch(exception){}
}
function checkUserOk(){
if (xmlHttp.readyState == 4) {
try{
var response = xmlHttp.responseText;
var alertObj = document.getElementById("reg_alert");
alertObj.innerHTML=response;
}catch(exception){}
}
}
</script>
<form name="form1" action="" method="post">
City<input type="text" name="username" id="username" size="25" >
<input type="button" name="check" value="检查唯一性" onClick=" checkUser('username')">
<span id="reg_alert" class="red_txt"> </span>
</form>
test.asp
<%
Response.ContentType = "text/html"
Response.Charset = "GB2312"
username=trim(request("username"))
if username="aaa" then
response.Write("ok")
else
response.Write("false")
end if
%>
相关文章推荐
- [Ajax]AJAX的简单应用(加法运算示例)
- ajax 小例子 示例 简单应用 如何使用
- 简单应用prototype的Ajax代理示例
- AJAX基础应用的简单示例
- Ajax简单应用示例: XMLHttpRequest对象实例化方式及调用
- Ajax简单示例应用,一看就会用!
- AJAX的简单应用(加法运算示例)
- AJAX的简单应用(加法运算示例)
- [Ajax]AJAX的简单应用(加法运算示例)
- Ajax简单示例,用来实时刷新服务器内存
- 简单了解AJAX,AJAX封装与应用
- Ajax简单应用,检测用户名是否存在
- (40)简单的Ext.Ajax.request示例
- Ajax -- 原理及简单示例
- VS2005 + VSS6.0 简单应用示例
- ajax小demo---JSONP 跨域原理及简单应用
- ajax的简单应用及filter的编写
- AJAX在VS2005中的简单应用
- AJAX最简单示例
- vue-router单页应用简单示例