window.XMLHttpRequest is undefined in IE7/IE8

前端 未结 3 1030
粉色の甜心
粉色の甜心 2020-12-18 11:21

Value of window.XMLHttpRequest is Undefined when i run my application even in IE7 or IE8, Is there anything i have to enable in IE7 to make it work.

Thanks

相关标签:
3条回答
  • 2020-12-18 11:36

    I enabled the native XMLHTTP support from internet options, after this the my code started working fine.

    0 讨论(0)
  • 2020-12-18 11:57

    You can do something like this:

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

    I recommend looking at an AJAX library though, life is much easier in jQuery, ExtJS, MooTools, whatever you prefer.

    0 讨论(0)
  • 2020-12-18 12:02

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

    var xhr = (function(){
        try{
            return new(this.XMLHttpRequest||ActiveXObject)('MSXML2.XMLHTTP.3.0');
        } catch(e) {};
    }());
    
    0 讨论(0)
提交回复
热议问题