问题:如何解决在ie下显示正常,火狐下不显示的问题!说明:在我的项目中 需要在前台页面中 通过js调用后台数据库中的广告信息  解决方案如下  
通过js调用方法 GetAD(htmlid, id) 指向后台处理程序"Handler.ashx?id=" + id;  后台处理程序根据传过来的id去数据库检索对应的广告内容 并返回内容  
前台接收内容信息并还原显示 现在问题是  在ie下功能都完好  但是在火狐下面就压根不显示调用的广告代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
     <script type="text/javascript">
        var xmlHttp;
        function createXMLHttpRequest()
        {
            try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e2) {
                    xmlHttp = false;
                }
            }
            if (!xmlHttp && typeof XMLHttpRequest != "udefined") {
                xmlHttp = new XMLHttpRequest();
            }        }
        function GetAD(htmlid, id)
        {
            createXMLHttpRequest();
            var url = "Handler.ashx?id=" + id;
            xmlHttp.open("POST",url,false);
            xmlHttp.onreadystatechange = function() { showResult(htmlid) };
//            xmlHttp.onreadystatechange = showResult;
            xmlHttp.send(null);
        }
        function showResult(htmlid)
//          function showResult()
        {
            if(xmlHttp.readyState==4)
            {
                if (xmlHttp.status == 200) {
                    document.getElementById(htmlid).innerHTML = xmlHttp.responseText;
//                    document.write(xmlHttp.responseText);
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">    
  <div id="div1"><script type="text/javascript">GetAD('div1',3);</script></div>  </form>
</body>
</html>

解决方案 »

  1.   

    xmlHttp.open("POST",url,true);
    试一下
    不行就
    xmlHttp.open("GET",url,true);
      

  2.   

    xmlHttp.open("POST",url,false);  你POST的url呢?没赋值吧
      

  3.   

    post数据的写法  xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", dataBody.length);//没有表单数据可不要或者写0
      xmlHttp.setRequestHeader("Connection", "close");//关键
      

  4.   

    open下加上
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      

  5.   

    if (!xmlHttp && typeof XMLHttpRequest != "udefined") {
                    xmlHttp = new XMLHttpRequest();
                }
    另外,这个是什么意思啊?
    我的做法是这样的:function tw_xmlhttp(err)//提示发生错误的文件定位
    {
        alert("err:[xmlhttp.js]{"+ err.message + "}");
    }
    //------------------------------------------------------------------------------------------
    function xml_http(request,sURL,open_parameter)
    {   
        try{
        //--------------
            var xmlhttp = null;
            var ProgID  = new Array( "MSXML2.XMLHTTP","Microsoft.XMLHTTP","MSXML2.XMLHTTP.3.0" );
            
            if( typeof( XMLHttpRequest )!="undefined"  )
            {
                try{
                    xmlhttp = new XMLHttpRequest();
                }
                catch( err ){
                    
                }
            }
            else
            {
                for(i=0;i<ProgID.length;i++)
                {   
                    try
                    {
                        
                        xmlhttp = new ActiveXObject(ProgID[i]);
                        if(xmlhttp != null)
                        {   //alert(ProgID[i]);
                            break;
                        }
                            
                    }
                    catch(e)
                    {   xmlhttp = null;
                        continue;
                    }
                };
            }
            if(xmlhttp == null)
            {   alert("xmlhttp建立失败!");
                return null;
            }
            xmlhttp.open(request,sURL,open_parameter);
            xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
            return xmlhttp;
        //--------------
        }catch(err){tw_xmlhttp(err +"::xml_http()" );}
    }
      

  6.   

     xmlHttp.open("POST",url,false);
    =>
     xmlHttp.open("get",url,false);