标题:求一个ajax做数据验证的实例
取消只看楼主
yoyodo
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2005-12-8
 问题点数:0 回复次数:0 
求一个ajax做数据验证的实例

大概要mvc模型吧,用javabean做数据库操作
还有Login.java 和DataBean.java的代码不会.
谁能给个猜考一下

以下是login.htm的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>首页</title>
<script type="text/javascript">
var xmlHttp;

//创建httpRequest请求
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

function userNameCheck() {
var userName = document.getElementById("userName").value;

if(userName == "") {
window.alert("用户名不能为空.");
document.form1.userName.focus();
return false;
}
else {
var url = "Login?userName=" + userName + "&ts=" + new Date().getTime();
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleAddStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function handleAddStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200 || xmlHttp.status == 0) {
var mes = xmlHttp.responseXML.getElementsByTagName("message")[0].firstChild.data;
var val = xmlHttp.responseXML.getElementsByTagName("passed")[0].firstChild.data;
setMessage(mes, val);
}
else {
alert(xmlHttp.status);
alert("Error while adding employee.");
}
}
}

function setMessage(message, isValid) {
var messageArea = document.getElementById("showMessage");
var fontColor = "red";

if (isValid == "true") {
fontColor = "green";
}
messageArea.innerHTML = "<font color=" + fontColor + ">" + message + " </font>";
}
</script>
</head>

<body>
<center>
<br /><br />
<table>
<form action="#" name="form1">
用户名: <input type="text" size="15" name="userName" onblur="userNameCheck();" id="userName"/>
&nbsp;&nbsp;<a href="reg?action=reg">注册</a><br />
密&nbsp;&nbsp;码:<input type="password" size="15" name="usePassword" id="password"/><br />
<input type="button" value="登录" name="submit" />
</form>
<div id="showMessage"></div>
</table>
</center>
</body>
</html>

搜索更多相关主题的帖子: ajax 实例 数据库 DTD 
2006-08-11 22:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-83510-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.813360 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved