为什么只在ie上好使,在火狐上不好使呢?
var xmlhttp;
     function createHTTP()
     {
       //根据不同的浏览器创建XMLHttpRequest
        if(window.ActiveXObject)
        {
           xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest) //ff,safari
        {
           xmlhttp=new XMLHttpRequest();
        }
     }
     //开始调用
     function startHTTP()
     {
       //创建对象
        createHTTP();
        //状态变化与事件挂钩
        xmlhttp.onreadystatechange=StateDO;
        //获取XML文件的数据
        xmlhttp.open("GET","XMLFile.xml",true);
        //不带任何参数
        xmlhttp.send(null);
     }
     function StateDO()
     {
     //判断是否是完成状态
       if(xmlhttp.ReadyState==4)
         {
         //判断是否执行成功
           if(xmlhttp.Status==200)
           {
           //更新页面上的某元素
              document.getElementById("mytext").innerText=xmlhttp.responsetext;
           }
         }
     }

解决方案 »

  1.   


    javascript对大小写是敏感的。ie兼容性比较强,会帮你处理,ff就不行了。
    xmlhttp.ReadyState应为:xmlhttp.readystate
    xmlhttp.Status 应为;xmlhttp.status
    xmlhttp.responsetext 应为xmlhttp.responseText还有,
    getElementById("mytext").innerText 只是ie的属性,通用的应该写:
    getElementById("mytext").innerHTML
      

  2.   

    if(window.ActiveXObject)
            {
               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest) //ff,safari
            {
               xmlhttp=new XMLHttpRequest();
            }修改为:
    if(window.ActiveXObject)
            {
               xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if(window.XMLHttpRequest) //ff,safari
            {
               xmlhttp=new XMLHttpRequest("Msxml2.XMLHTTP");
            }
      

  3.   

    ok了,谢谢!
    二楼的,我不用改也可以,不知道Msxml2.XMLHTTP是什么东西啊?
      

  4.   

    ckpckphaha(赫尔墨斯神杖) ( ) 信誉:96    Blog   加为好友  2007-6-4 17:25:34  得分: 90  
    居然升星星了