关闭

Ajax 检验用户唯一性

标签: ajaxxmlhttprequestfunctioninputbrowserhtml
969人阅读 评论(0) 收藏 举报

//vu.htm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>validator user</title>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript">
var http_request=false;
function send_request(method,url){
http_request=false;
// inital HttpRequest
if(window.XMLHttpRequest){//Mozilla
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType){//set Mime
http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){//IE Browser,use lasted version

var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
for(var n = 0; n < MSXML.length; n ++)
{
try{
http_request = new ActiveXObject(MSXML[n]);
http_request.setRequestHeader('Content-Type', 'text/html; charset=gb2312');//相当于iFrame

break;
}
catch(e){}
}//End IE
}// End inital HttpRequest

if(!http_request){//Error, Creat object fail
 window.alert("不能创建XMLHttpRequest对象实例")
 return false;
}
http_request.onreadystatechange = processRequest;
//get post or head, and asychFlag??
http_request.open(method, url,true);
http_request.send(null);
}// END send_request()

function processRequest(){
if(http_request.readyState == 4){
if(http_request.status == 200){
document.all["message"].innerHTML= http_request.responseText;}
}
}// End processRequest()

 function userCheck() {
 var f = document.form1;
 var username = f.username.value;
 if(username=="") {
  window.alert("用户名不能为空。");
  f.username.focus();
  return false;
 }
 else{
 send_request('GET','check.asp?username='+username);
 }
}
</script>
</head>

<body>
<form name="form1">
用户名:
<input name="username" type="text" id="username">
<input type="button" name="Submit" value="提交" onClick="userCheck()">
</form>
<div id="message"></div>
</body>
</html>

//check.asp

<% response.Charset="GB2312"%>
<%
u_name=request("username")
if u_name="test" then
response.Write(u_name&"已经被注册")
else
response.Write("恭喜,您选的帐号 "&u_name&" 可以注册!")
end if
%>

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1404965次
    • 积分:20190
    • 等级:
    • 排名:第415名
    • 原创:448篇
    • 转载:1067篇
    • 译文:4篇
    • 评论:143条
    文章存档
    最新评论