<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<script type="text/javascript">
var xmlHttpRequest;
function checkNameExists()
{
with(document.Register)
{
var user=loginNane.value;
var pass=loginPass.value;
if(user==null ||user=="")
{
alert("用户名不能为空")
}
var url="RegisterServlet";
xmlHttpRequest=createXMLHttpRequest;
xmlHttpRequest.onreadystatechange=huidiaohanshu;
xmlHttpRequest.open("GET",url,true);
xmlHttpRequest.send(null);
}
}
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}else
{
return new XMLHttpRequest();
}
}
function huidiaohanshu()
{
if(xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200)
{
var result=xmlHttpRequest.responseText;
if(result=="用户名已经存在")
{
alert(result);
}else
{
alert("用户名可以使用");
}
}
}
</script>
</head>
<body>
<center>
<form method="post" name="Register" action="RegisterServlet">
用户注册<br>
用户名:<input name="loginNane" onblur="checkNameExists()"><br>
密 码:<input name="loginPass" ><br>
<input type="submit" onclick="RegisterSubmit()" value="提交">
<a href="index.jsp">返回首页</a>
</form>
</center>
</body>
</html>
我的是IE7浏览器
------解决方案--------------------
------解决方案--------------------
xmlHttpRequest=createXMLHttpRequest;
貌似楼主没有家括号
xmlHttpRequest=createXMLHttpRequest();