<script type="text/javascript">
function check(){
var account=document.loginForm.account.value
var pwd=document.loginForm.password.value
var xmlHttp;
if (window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else if (window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open("post","ajax.jsp?account="+account+"&password="+pwd,true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
xm.innerHTML=xmlHttp.responseText
}else{
xm.innerHTML="正在登录,请稍等..."
}
}
xmlHttp.send();
}
</script>
<form name="loginForm">
姓名<input type="text" name="account" ><BR>
密码<input type="password" name="password"><BR>
<input type="button" value="OK" οnclick="check()">
</form>
<hr>
<span id="xm"></span>
</body>
ajax.jsp内容
<%
String account= request.getParameter("account");
String pwd= request.getParameter("password");
if(account.equals(pwd)){
out.println("登录成功");
}
else{
out.println("登录失败");
}
%>
function check(){
var account=document.loginForm.account.value
var pwd=document.loginForm.password.value
var xmlHttp;
if (window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}else if (window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlHttp.open("post","ajax.jsp?account="+account+"&password="+pwd,true);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
xm.innerHTML=xmlHttp.responseText
}else{
xm.innerHTML="正在登录,请稍等..."
}
}
xmlHttp.send();
}
</script>
<form name="loginForm">
姓名<input type="text" name="account" ><BR>
密码<input type="password" name="password"><BR>
<input type="button" value="OK" οnclick="check()">
</form>
<hr>
<span id="xm"></span>
</body>
ajax.jsp内容
<%
String account= request.getParameter("account");
String pwd= request.getParameter("password");
if(account.equals(pwd)){
out.println("登录成功");
}
else{
out.println("登录失败");
}
%>