glorytao 发表于 2013-1-23 02:54:36

AJAX

<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" >

</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("登录失败");
}

%>
页: [1]
查看完整版本: AJAX