代码之家  ›  专栏  ›  技术社区  ›  ARV

window.xmlhttpRequest在IE7/IE8中未定义

  •  3
  • ARV  · 技术社区  · 15 年前

    即使在IE7或IE8中运行应用程序时,window.xmlhttpRequest的值也未定义,在IE7中是否需要启用任何功能才能使其正常工作。

    谢谢

    3 回复  |  直到 11 年前
        1
  •  8
  •   yckart Matthew Crumley    11 年前

    你可以这样做:

    if (!window.XMLHttpRequest) {
      window.XMLHttpRequest = function() {
        return new ActiveXObject('Microsoft.XMLHTTP');
      };
    }
    

    不过,我建议查看Ajax库,jquery、extjs、mootools中的生活要轻松得多,无论您喜欢什么。

        2
  •  2
  •   ARV    14 年前

    我从Internet选项启用了本机XMLHTTP支持,之后我的代码开始正常工作。

        3
  •  1
  •   yckart Matthew Crumley    11 年前

    https://gist.github.com/jed/993585/#comment-40084

    var xhr = (function(){
        try{
            return new(this.XMLHttpRequest||ActiveXObject)('MSXML2.XMLHTTP.3.0');
        } catch(e) {};
    }());