Skip to content

Commit 10ee557

Browse files
committed
Initial commit
0 parents  commit 10ee557

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

README.markdown

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# jQuery.iecors
2+
3+
This is a new "transport" (or driver) for jQuery that allows the browser-like software known as IE 8 and 9 to make cross-domain AJAX requests using Microsoft's XDomainRequest object. No need for JSONP!
4+
5+
# Installation
6+
7+
Copy jquery.iecors.js into your javascripts directory. Include it in your web page.
8+
9+
# Usage
10+
11+
```javascript
12+
$.ajax({ ... });
13+
```
14+
15+
Yes, it's that simple! IE will try to use standard XHR, but will fail because it can't make cross-domain requests. Then, it will try this snazzy new driver and succeed.
16+
17+
# License
18+
19+
The MIT License
20+
21+
Copyright (c) 2011 Derek Kastner
22+
23+
Permission is hereby granted, free of charge, to any person obtaining a copy
24+
of this software and associated documentation files (the "Software"), to deal
25+
in the Software without restriction, including without limitation the rights
26+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27+
copies of the Software, and to permit persons to whom the Software is
28+
furnished to do so, subject to the following conditions:
29+
30+
The above copyright notice and this permission notice shall be included in
31+
all copies or substantial portions of the Software.
32+
33+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39+
THE SOFTWARE.

jquery.iecors.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(function( jQuery ) {
2+
// Create the request object
3+
// (This is still attached to ajaxSettings for backward compatibility)
4+
jQuery.ajaxSettings.xdr = function() { return new window.XDomainRequest(); };
5+
6+
// Determine support properties
7+
(function( xdr ) {
8+
jQuery.extend( jQuery.support, { iecors: !!xdr, });
9+
})( jQuery.ajaxSettings.xdr() );
10+
11+
// Create transport if the browser can provide an xdr
12+
if ( jQuery.support.iecors ) {
13+
14+
jQuery.ajaxTransport(function( s ) {
15+
var callback;
16+
17+
return {
18+
send: function( headers, complete ) {
19+
var xdr = s.xdr();
20+
21+
xdr.onload = function() {
22+
var headers = { 'Content-Type': xdr.contentType };
23+
complete(200, 'OK', { text: xdr.responseText }, headers);
24+
};
25+
26+
// Apply custom fields if provided
27+
if ( s.xhrFields ) {
28+
xhr.onerror = s.xhrFields.error;
29+
xhr.ontimeout = s.xhrFields.timeout;
30+
}
31+
32+
xdr.open( s.type, s.url );
33+
34+
// XDR has no method for setting headers O_o
35+
36+
xdr.send( ( s.hasContent && s.data ) || null );
37+
},
38+
39+
abort: function() {
40+
xdr.abort();
41+
}
42+
};
43+
});
44+
}
45+
})( jQuery );

0 commit comments

Comments
 (0)