首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

看看这段代码有啥异常

2012-05-23 
【求助】看看这段代码有啥错误%@ page languagejava importjava.util.* pageEncodingGBK%html

【求助】看看这段代码有啥错误
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<html>
  <head>  
  <title>页面无刷新登录</title>
  <script type="text/javascript">
  
  var xmlHttp;
  function createXmlHttp(){
  try{
  xmlHttp=new XMLHttpRequest();
  }catch(e){
  try{
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"):
  }catch(e){
  try{
  xmlHttp=new ActiveObject("Microsoft.XMLHTTP");
  }catch(e){
  alert("浏览器不支持Ajax!");
  }
  }
  }
  }
  }
   
  var name;
  var pwd;
  function check(){
  name=document.getElementById("uname").value;
  pwd=document.getElementById("upwd").value;
  if(name.length==0){
  document.getElementById("showName").innerHTML="用户名不能为空!";
  return false;
  }if(pwd.length==0){
  document.getElementById("showPwd").innerHTML="密码不能为空!";
  return false;
  }
  return true;
  }

  function doAjax(){
  createXmlHttp();
  if(xmlHttp!=null){
  if(check()){
  xmlHttp.open("post","<%=request.getContextPath() %>/login?uname="+name+"&upwd="+pwd,true);
  xmlHttp.setRequestHeader("Content-type","appliation/x-www-form-urlencoded");
  xmlHttp.onreadystatechange=processchange;
  xmlHttp.send(null);
  }
  }
  }
   
  function processchange(){
  if(xmlHttp.readyState == 4){
  if (xmlHttp.status == 200) {
  var mes=xmlHttp.reponseText;
  if (mes == "Y") {
document.getElementById("login").innerHTML = "欢迎!";
} else {
document.getElementById("login").innerHTML = "失败!";
}
  }
  }
  }
  </script>
  </head>
  
  <body>
  <div id="login">
  <table>
  <tr>
  <td>用户名:</td>
  <td><input type="text" id="uname" name="uname" /></td>
  <td id="showName"></td>
  </tr>
  <tr>
  <td>密码:</td>
  <td><input type="password" id="upwd" name="upwd"/></td>
  <td id="showPwd"><br></td>
  </tr>
  <tr>
  <td><input type="button" value="登录" onclick="doAjax()"/></td>
  </tr>
  </table>
  </div>
  </body>
</html>


[解决办法]
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"):
这句应该是分号;
[解决办法]
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"):
这个地方是个错误,你那里没有报错吗?
[解决办法]

JScript code

  var xmlHttp;  function createXmlHttp(){  try{      xmlHttp=new XMLHttpRequest();  }catch(e){      try{          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      }catch(e){          try{                  xmlHttp=new ActiveObject("Microsoft.XMLHTTP");          }catch(e){                   alert("浏览器不支持Ajax!");                   }               }            }  }
[解决办法]
经过测试 xmlHttp已存在!通过!马虎原因!

热点排行