【问题标题】:Error showing unknown name in javascript在 javascript 中显示未知名称时出错
【发布时间】:2011-02-17 21:45:29
【问题描述】:

如果我从下拉框中选择一个选项,则会调用 onchange 功能,它具有 功能 retrieveurl(url,formbean);编写的代码。

它调用了用 javascript 编写的 ajax,它无法检测到我的浏览器版本,即 IE6.0.2900....

下面的代码我用过...

try {

  req = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

   try {

      req = new ActiveXObject("Microsoft.XMLHTTP");

   } catch {

       alert('second catch');
   }

}

当我调试它涉及到第二个捕获警报

谁能帮我解决这个问题??

【问题讨论】:

  • 难道这与关于activeX的IE安全参数有关吗?

标签: javascript ajax internet-explorer-6


【解决方案1】:

据我所知,这应该适用于 IE6。但是您在第二个捕获中缺少 (e) 参数,它可能应该在那里。也许这是把事情搞砸了?对不起,我无法检查,没有 IE6。

【讨论】:

    【解决方案2】:

    第二个 catch 语句中错过了 catch*(e)*

    try
    {
        req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    
    catch(e)
    {
        try
        {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
    
        catch(e)
        {
            alert('second catch');
        }
    }
    

    更新: 我还建议使用所有版本的 MS XML HTTP 对象

    function getHTTPRequest () 
    {
        var xmlHttp;
        try 
        {
            // Firefox, Chrome, Opera, IE 8
            xmlHttp = new XMLHttpRequest();
        } 
        catch (err) 
        {
            // IE and possible XML HTTP ProIDs
            var XmlHttpVersions = new Array(
                                "Msxml2.XMLHTTP.7.0",
                                "Msxml2.XMLHTTP.6.0",
                                "Msxml2.XMLHTTP.5.0",
                                "Msxml2.XMLHTTP.4.0",
                                "MSXML2.XMLHTTP.3.0",
                                "MSXML2.XMLHTTP",
                                "Microsoft.XMLHTTP"
                                );
            for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
            {
                try 
                {
                    xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
                }
                catch(err) {} //Ignore
    
    
            }        
        }
    
        if(!xmlHttp) 
        {
            alert("No HttpRequest supported");
        }
        else 
        {
            return xmlHttp;
        }
    }
    
    var xhr = getHTTPRequest();
    

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      • 1970-01-01
      • 2021-12-15
      • 2016-06-15
      • 1970-01-01
      相关资源
      最近更新 更多