Created
October 16, 2014 14:23
-
-
Save vikynandha-zz/17d4b7553981ee99c05c to your computer and use it in GitHub Desktop.
jQuery patch for cross-domain requests in IE <= 9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( window.XDomainRequest ) { | |
jQuery.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 = jQuery.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 = jQuery.noop; | |
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 = jQuery.noop; | |
xdr.abort(); | |
} | |
} | |
}; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment