日期:2014-05-16 浏览次数:20711 次
<script type="text/javascript" src="scripts/reg.js">
</script>
</head>
<body>
<form>
用户名<input type="text" name="username" id="username"/>
<input type="text" id="hid" style="border-width:0;color: red"><br/>
<input type="button" value="yanzheng" onclick="sub()"/>
</form>
</body>
<%
String usr=(String)request.getAttribute("username");
if(usr.trim().equals("mmt")){
out.print("用户名不可用");
}else{
out.print("用户名可用");
}
%>
var xmlobj=null;
function sub(){
xmlobj=createObj();
if(xmlobj){
var url="ajaxEx/registerEx.jsp?username="+getNa("username").value;
alert(url);
xmlobj.open("get",url,true);
xmlobj.onreadystatechange=callBack;
xmlobj.send(null);
}else{
alert("no");
}
}
//callback
function callBack(){
//alert(xmlobj.readyState);
if(xmlobj.readyState==4){
getNa("hid").value=xmlobj.responseText;
}
}
function getNa(id){
return document.getElementById(id);
}
function createObj(){
var xmlhttp=null;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlhttp;
}