本人新学AJAX.做了个习题碰到点奇怪问题
题目的要求是按一个按钮显示XML上的表格.
以下是我的HTML的内容
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>innerHTML.html</title>
    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 <script type="text/javascript">
  var xmlHttp;
  function createXMLHttpRequest()
  {
if (window.ActiveXObject)//判断是否是IE,如果是则创建一个IEHTTP的实例,如果不是则跳转到ELSE IF
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)//判断是否具备XMLHttpRequest对象,如果具备则创建它的实例
{
 xmlHttp=new XMLHttpRequest();
}
  }
  function startRequest()
  {
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET","innerHTML.xml",true);
xmlHttp.send(null);
  }
  function handleStateChange()
  {
if(xmlHttp.readyState==4)
{
if(xmlHttp.stutus==200)
{
document.getElementById("results").innerHTML=xmlHttp.responseText;
}
}
  }  </script>
  </head>
  
  <body>
    <form action="#">
    <input type="button" value="serch" onclick="startRequest();"/>
    </form>
    <div id="results"></div>
  </body>
</html>以下是XML的内容
<?xml version="1.0" encoding="UTF-8"?>
<xml-body>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Location</th>
<th>Time</th>
</tr>
<tr>
<th>fang</th>
<th>dock</th>
<th>9:00</th>
</tr>
<tr>
<th>huang</th>
<th>east</th>
<th>2:00</th>
</tr>
<tr>
<th>zz</th>
<th>taa</th>
<th>21:00</th>
</tr>
</tbody>
</table>
</xml-body>运行后就是按了按钮没反映也不出错。请问该如何解决是不是没弄对?谢谢高手

解决方案 »

  1.   

    你的
    xmlHttp.open("GET","innerHTML.xml",true);
    xmlHttp.send(null);是向哪发送?服务器端的处理代码呢?
      

  2.   

    xmlHttp.responseXML.getElementsByTagName("data")[0].firstChild.data;
      

  3.   

    初学,对Html做了跟踪:
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <title>innerHTML.html</title>
        
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=gb_2312">
     <script type="text/javascript">
      var xmlHttp;
      function createXMLHttpRequest()
      {
    if (window.ActiveXObject)//判断是否是IE,如果是则创建一个IEHTTP的实例,如果不是则跳转到ELSE IF
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(window.XMLHttpRequest)//判断是否具备XMLHttpRequest对象,如果具备则创建它的实例
    {
     xmlHttp=new XMLHttpRequest();
    }
      }
      function startRequest()
      {
      alert("我们调用了startRequest()函数!");
    createXMLHttpRequest();
    //xmlHttp.onreadystatechange=handleStateChange;
    xmlHttp.open("GET","innerHTML.xml",true);
    xmlHttp.onreadystatechange=handleStateChange;
    xmlHttp.send(null);
      }
      function handleStateChange()
      {
      alert("我们调用了 handleStateChange()");
    if(xmlHttp.readyState==4)
    {
    alert("readyState=4");
    //if(xmlHttp.stutus==200)
    //{
    alert(xmlHttp.status);
    document.getElementById("results").innerHTML=xmlHttp.responseText;
    //}
    }
      }  </script>
      </head>
      
      <body>
        <form action="">
        <input type="button" value="serch" onClick="startRequest();"/>
        </form>
        <div id="results"></div>
      </body>
    </html>
    在打印alert(xmlHttp.status);时显示值为:0,所if以下面语句不执行;
    为什么xmlHttp.status为何取值错误,还未找到原因.
      

  4.   

    郁闷。研究到现在还是不可以显示.回答2楼的朋友我的返回是返回XML里的内容,我是刚学
      

  5.   

    大家帮帮忙啊。这个问题解决掉我就结了。现在我就是按钮的ONCLICK事件按了没反映啊。到底哪里错了.哎
      

  6.   

    呵呵,小兄弟,还在郁闷呢?你有个字母写错了if(xmlHttp.stutus==200)
    {
    document.getElementById("results").innerHTML=xmlHttp.responseText;
    }是status  不是stutus