-
Notifications
You must be signed in to change notification settings - Fork 11
/
jquery.xdr.js
43 lines (43 loc) · 1.72 KB
/
jquery.xdr.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
(function ($) {
"use strict";
if (window.XDomainRequest) {
$.ajaxTransport(function(s) {
if (s.crossDomain && s.async) {
if (s.timeout) {
s.xdrTimeout = s.timeout;
delete s.timeout;
}
var xdr;
return {
send: function(_, complete) {
function callback(status, statusText, responses, responseHeaders) {
xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
xdr = undefined;
complete(status, statusText, responses, responseHeaders);
}
xdr = new XDomainRequest();
xdr.onload = function() {
callback(200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType);
};
xdr.onerror = function() {
callback(404, "Not Found");
};
xdr.onprogress = function () {};
xdr.ontimeout = function() {
callback(0, "timeout");
};
xdr.timeout = s.xdrTimeout || Number.MAX_VALUE;
xdr.open(s.type, s.url);
xdr.send((s.hasContent && s.data) || null);
},
abort: function() {
if (xdr) {
xdr.onerror = $.noop;
xdr.abort();
}
}
};
}
});
}
})(jQuery);