代码在FF下测试成功,但在IE下不成功(IE6.7.8均测试不成功)
var http_request=false;
  function send_request(url){//初始化,指定处理函数,发送请求的函数
    http_request=false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest){//Mozilla浏览器
 http_request=new XMLHttpRequest();
 if(http_request.overrideMimeType){//设置MIME类别
   http_request.overrideMimeType("text/xml");
 }
}
else if(window.ActiveXObject){//IE浏览器
 try{
  http_request=new ActiveXObject("Msxml2.XMLHttp");
 }catch(e){
  try{
  http_request=new ActiveXobject("Microsoft.XMLHttp");
  }catch(e){}
 }
    }
if(!http_request){//异常,创建对象实例失败
 window.alert("创建XMLHttp对象失败!");
 return false;
}
http_request.onreadystatechange=processrequest;
//确定发送请求方式,URL,及是否同步执行下段代码
    http_request.open("GET",url,true);
http_request.send(null);
  }
  //处理返回信息的函数
  function processrequest(){
   if(http_request.readyState==4){//判断对象状态
     if(http_request.status==200){//信息已成功返回,开始处理信息
  document.getElementById(reobj).innerHTML=http_request.responseText;
 }
 else{//页面不正常
  alert("您所请求的页面不正常!");
 }
   }
  }
  function getclass(obj){
   var pid=document.form1.select1.value;
   var act="do1";
   document.getElementById(obj).innerHTML="<option>loading...</option>";
   send_request('doclass.php?pid='+pid+'&act='+act);
   reobj=obj;
  }  function getclass2(obj){
   var pid=document.form1.select2.value;
   var act="do2";
   document.getElementById(obj).innerHTML="<option>loading...</option>";
   send_request('doclass.php?pid='+pid+'&act='+act);
   reobj=obj;
  }
 <script language="javascript" src="ajaxmenu.js"></script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ajax2级联动菜单演示</title>
</head><body>
<form name="form1">
<select name="select1" id="class1" style="width:100;" onChange="getclass('class2');">
  <option selected="selected"></option>
  <option value="2">大类1</option>
  <option value="4">大类2</option>
</select>
<select name="select2" id="class2" style="width:100;" onChange="getclass2('class3');">
</select>
<select name="select3" id="class3" style="width:100;">
</select>
</form>
</body>
</html>

解决方案 »

  1.   

    LZ你是不是没通过服务器测试的
    IE下ajax需要通过服务器来测试
      

  2.   

    修改以下部分可解决ie的问题
    1. 定义全局变量 var reobj;
    2. reobj=obj; 放到send_request()上面;
    3. send_request参数中加一个时间戳防止缓存 "...&" + escape(new Date())
    4. ie里不能用innerHTML更新select, 可以返回ajax可以连<select>标签一起返回,
    用outerHTML更新 document.getElementById(reobj).outerHTML=http_request.responseText;
      

  3.   

    谢谢楼上的,我定义全局变量后在FF下测试二级菜单变成loading...一直读不出来数据。麻烦你写一下这个函数正确的写法。function getclass(obj){
       var reobj;
       var pid=document.form1.select1.value;
       var act="do1";
       document.getElementById(obj).innerHTML="<option>loading...</option>";
       reobj=obj;
       send_request('doclass.php?pid='+pid+'&act='+act);
       
      }
      

  4.   

    var reobj;不是加在函数里,是加在var http_request=false;前面
      

  5.   

    加在var http_request=false;前面了现在改成这样了: function getclass(obj){
       var id=document.form.areaid.value;
       var act="do1";
       document.getElementById(obj).outerHTML=http_request.responseText;
       reobj=obj;
       send_request('doclass.php?pid='+id+'&act='+act);
       
      }在IE提示document.getElementById为空或不是对象我对JS一窍不通哈,只是做PHP的。谢谢好心的hookee
      

  6.   

    另外 document.getElementById(obj).innerHTML=" <option>loading... </option>"; ie无效
    document.getElementById(obj).outerHTML="<select name='select1' id='" + obj + "' style='width:100;'><option>loading... </option></select>"; 
      

  7.   

    function getclass(obj){
      var id=document.form.areaid.value;
      var act="do1";
      document.getElementById(obj).outerHTML="<select name='select1' id='" + obj + "' style='width:100;'><option>loading... </option></select>";
      reobj=obj;
      send_request('doclass.php?pid='+id+'&act='+act);
     
      } 改成这样了,还是不行,FF下可以用,IE下查询不到值测试地址:http://119.45.64.250/cms/test  谢谢
      

  8.   


    http_request.responseText返回的是 <option>(内容)</option>IE下document.getElementById(reobj).outerHTML=  //重新构造select 例如<select name='select1' id='"+obj+"' style='width:100;'><option>loading... </option></select>;
      

  9.   

    我的最终目的是一个联动菜单具体该怎么改?本人对JS确实不懂。。function getclass(obj){
      var id=document.form.areaid.value;
      var act="do1";
      document.getElementById(obj).outerHTML="<select name='select1' id='" + obj + "' style='width:100;'><option value='1'>大类1</option><option value='3'>大类2</option></select>"; 
      reobj=obj;
      send_request('doclass.php?pid='+id+'&act='+act);  } ???
      

  10.   

    ie下的select不支持使用innerHTML来更新options对象需要使用select.options.add(new Option('显示的值','option的value'))自己修改过来下面一个简单的测试,根本没有效果<select name="select3" id="class3" style="width:100;">
    </select>
    <script language="javascript">window.onload=function(){
    document.getElementById('class3').innerHTML='<option>loading...</option>'}
    </script>
    下面是一个大概的修改
    function processrequest(){
       if(http_request.readyState==4){//判断对象状态
         if(http_request.status==200){//信息已成功返回,开始处理信息
    //=============================这里需要修改过,要使用sel.options.add的来添加option
    //你可以返回一个json对象的数组的字符串表示的对象,如 [{txt:'显示的值',value:'value'},{txt:'显示的值',value:'value'}]
    //然后eval生产数组对象,然后遍历数组向select中使用sel.options.add来添加option
          //document.getElementById(reobj).innerHTML=http_request.responseText;var o=document.getElementById(reobj)
    ,arr=eval('('+http_request.responseText+')');//eval生产数组对象
    o.options.length=0//要注意先清空原来的option
    for(var i=0;i<arr.length;i++)sel.options.add(new Option(arr[i].txt,arr[i].value))//===========
         }
         else{//页面不正常
          alert("您所请求的页面不正常!");
         }
       }
      }
      function getclass(obj){
       var pid=document.form1.select1.value;
       var act="do1";
       var o=document.getElementById(obj)
    o.options.length=0//===========这样设置来清空options
    o.options.add(new Option('loading...'))//===========
    //========document.getElementById(obj).innerHTML="<option>loading...</option>";
       send_request('doclass.php?pid='+pid+'&act='+act);
       reobj=obj;
      }  function getclass2(obj){
       var pid=document.form1.select2.value;
       var act="do2";
       var o=document.getElementById(obj)
    o.options.length=0//===========这样设置来清空options
    o.options.add(new Option('loading...'))//===========
      //========== document.getElementById(obj).innerHTML="<option>loading...</option>";   send_request('doclass.php?pid='+pid+'&act='+act);
       reobj=obj;
      }
      

  11.   

    用outerHTML更新时,http_request.responseText需要返回的是 
    <select name="select2" id="class2" style="width:100;" onChange="getclass2('class3');">
    <option>xxxx</option>
    </select>照上面4点改,ie下测试过是可以的.