日期:2014-05-16 浏览次数:20806 次
var xmlHttp;
function createXmlHttp(){
//表示当前浏览器不是ie,如ns,firefox
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
//验证用户ID是否存在
function validateUserId(field){
if(trim(field.value).length!=0){
createXmlHttp();
var url="user_validate.jsp?userId="+trim(field.value)+"&timeStamp="+new Date().getTime();
xmlHttp.open("GET",url,true);
//处理完成后自动调用
xmlHttp.onreadystatechange=function() { //匿名函数
if(xmlHttp.readyState == 4) { //Ajax引擎初始化成功
if (xmlHttp.status == 200) { //http协议成功
document.getElementById("userIdSpan").innerHTML = "<font color='red'>" + xmlHttp.responseText + "</font>";
}else {
alert("请求失败,错误码=" + xmlHttp.status);
}
}
};
//将参数发送到Ajax引擎
xmlHttp.send(null);
}else {
document.getElementById("userIdSpan").innerHTML = "";
}
}
?另外一个JSP页面:
<%
String userId = request.getParameter("userId");
out.println(userId);
if (UserManager.createInstance().findUserById(userId) != null) {
out.println("用户代码已经存在!");
}
%>
?