Skip to content

Instantly share code, notes, and snippets.

@xamgore
Created December 8, 2014 21:08
Show Gist options
  • Save xamgore/d0da8bb6cd305391054a to your computer and use it in GitHub Desktop.
Save xamgore/d0da8bb6cd305391054a to your computer and use it in GitHub Desktop.
cash js xhr ajax
var getXHR = function() {
    var http;
    try {
      http = new XMLHttpRequest;
        getXHR = function() {
          return new XMLHttpRequest;
        };
    }
    catch(e) {
      var msxml = [
        'MSXML2.XMLHTTP.3.0',
        'MSXML2.XMLHTTP',
        'Microsoft.XMLHTTP'
      ];
      for (var i=0, len = msxml.length; i < len; ++i) {
        try {
          http = new ActiveXObject(msxml[i]);
          getXHR = function() {
            return new ActiveXObject(msxml[i]);
          };
          break;
        }
        catch(e) {}
      }
    }
    return http;
  };
Hide full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment