当前位置: 代码迷 >> Java Web开发 >> 关于Ajax的问题
  详细解决方案

关于Ajax的问题

热度:205   发布时间:2010-04-11 10:08:57.0
关于Ajax的问题
刚学ajax
有什么低级错误还望直言
写了个简单的ajax程序
可是在页面文本框里输好字后点击其他地方
他都没反应
甚至我到我同学那弄了个调试成功了个ajax程序过来都会变的没反应的ajax程序
重新部署也没用
这是为什么呢?
是配置问题么?
百度了也没找到想要的答案
希望哪位能帮解释下么?


源程序如下:
<%@ page contentType = "text/html;charset = gb2312"%>
<%
String path=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC " - //W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href=" <%=basePath %>">
    <title>My JSP 'Test.jsp' starting page</title>
    <mata http - equiv = "pragma" content="no-cache">
    <mata http - equiv ="cache - control" content="no - cache">
    <mata http - equiv ="expires" content="0">
    <mata http - equiv ="keywords" content="keyword1,keyword2,keyword3">
    <mata http - equiv ="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>

<script language="javaScript">
var xMLHttpRequest=false;

function createXMLHttpRequest()
{
    if(window.XMLHttpRequest)  //Mozilla浏览器
    {
         xMLHttpRequest=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
    try{
          xMLHttpRequest=new ActiveXObject("Msxm12.XMLHTTP");
       }catch(e)
       {
       try{
             xMLHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
          }catch(e){}
       }
    }
}

function processResponse()
{
   if(xMLHttpRequest.readystate==4)    //判断对象状态
   {
     if(xMLHttpRequest.status==200)    //信息已经返回,开始处理信息
     {
       var res=xMLHttpRequest.responseText;
       //window.alert(res);
       document.getElementById("userlabel").innerText=res;
     }
     else   //页面不正常
     {
        window.alert("您请求的页面有异常!");
     }
   }
}

function usercheck()
{
   createXMLHttpRequest();
   
   xMLHttpRequest.open("GET","check?username="+document.registerform.username.value,true);
   xMLHttpRequest.onreadystatechange=processResponse;  //指定响应函数
   xMLHttpRequest.send(null);                          //发送请求
}  
      
</script>

  <body>
   
   <form name="registerform" action = "register" method="post">
   <p> 注册</p>
   <p>用户名:<input type="text" name="username" onblur="usercheck()">
   <label for=username id="userlabel">不能为空</label></p>
   <p>&nbsp;性别:<input type="radio" checked="checked" value="男" name = "sex"/>男
   <input type="radio" value="女" name="sex"/>女</p>
   <p>&nbsp;<input type="submit" value="注册"/></p>
   </form>   
  </body>
</html>



[ 本帖最后由 【赣】暴风 于 2010-4-11 12:30 编辑 ]
搜索更多相关主题的帖子: Ajax  

----------------解决方案--------------------------------------------------------
createXMLHttpRequest()函数改成
if(window.ActiveXObject)
    xMLHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
else
    xMLHttpRequest = new XMLHttpRequest();

----------------解决方案--------------------------------------------------------
回复 2楼 guoxhvip
嗯。。。
还真是这问题。。。。
谢谢了。。。
----------------解决方案--------------------------------------------------------
  相关解决方案