forked from erithmetic/jquery.iecors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.iecors.js
executable file
·46 lines (37 loc) · 1.22 KB
/
jquery.iecors.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
44
45
46
(function( jQuery ) {
// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xdr = function() {
return (window.XDomainRequest ? new window.XDomainRequest() : null);
};
// Determine support properties
(function( xdr ) {
jQuery.extend( jQuery.support, { iecors: !!xdr });
})( jQuery.ajaxSettings.xdr() );
// Create transport if the browser can provide an xdr
if ( jQuery.support.iecors ) {
jQuery.ajaxTransport(function( s ) {
var callback,
xdr = s.xdr();
return {
send: function( headers, complete ) {
xdr.onload = function() {
var headers = { 'Content-Type': xdr.contentType };
complete(200, 'OK', { text: xdr.responseText }, headers);
};
// Apply custom fields if provided
if ( s.xhrFields ) {
xhr.onerror = s.xhrFields.error;
xhr.ontimeout = s.xhrFields.timeout;
}
xdr.open( s.type, s.url );
// XDR has no method for setting headers O_o
xdr.send( ( s.hasContent && s.data ) || null );
},
abort: function() {
xdr.abort();
}
};
});
}
})( jQuery );