-
Notifications
You must be signed in to change notification settings - Fork 18
/
xhr.js
43 lines (38 loc) · 1.08 KB
/
xhr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/** @license MIT License (c) copyright 2013 original authors */
/**
* XHR polyfill / shims
*
* @author Brian Cavalier
* @author John Hann
*/
(function (global, define) {
define(function (require) {
"use strict";
var progIds;
// find XHR implementation
if (typeof XMLHttpRequest == 'undefined') {
// create xhr impl that will fail if called.
assignCtor(function () { throw new Error("poly/xhr: XMLHttpRequest not available"); });
// keep trying progIds until we find the correct one,
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
while (progIds.length && tryProgId(progIds.shift())) {}
}
function assignCtor (ctor) {
// assign global.XMLHttpRequest function
global.XMLHttpRequest = ctor;
}
function tryProgId (progId) {
try {
new ActiveXObject(progId);
assignCtor(function () { return new ActiveXObject(progId); });
return true;
}
catch (ex) {}
}
});
}(
typeof global != 'undefined' && global || this.global || this,
typeof define == 'function' && define.amd
? define
: function (factory) { module.exports = factory(require); }
));