Created
June 28, 2013 13:56
-
-
Save wallin/5884850 to your computer and use it in GitHub Desktop.
Drop-in jQuery-plugin for allowing cross domain ajax-calls in IE
This file contains hidden or 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
$.ajaxTransport((options, originalOptions, jqXHR) -> | |
if window.XDomainRequest | |
xdr = null | |
return { | |
send: (headers, completeCallback) -> | |
# Match protocol since XDR doesn't allow differences | |
if 'http:' is document.location.protocol | |
options.url = options.url.replace('https:', 'http:') | |
xdr = new XDomainRequest() | |
xdr.open options.type, options.url | |
xdr.timeout = 20000 | |
xdr.onprogress = -> | |
xdr.onload = -> | |
if @contentType.match(/\/xml/) | |
dom = new ActiveXObject("Microsoft.XMLDOM") | |
dom.async = false | |
dom.loadXML @responseText | |
completeCallback 200, "success", [ dom ] | |
else | |
completeCallback 200, "success", [ JSON.parse(@responseText) ] | |
xdr.ontimeout = -> | |
completeCallback 408, "error", [ "The request timed out." ] | |
xdr.onerror = -> | |
completeCallback 404, "error", [ "The requested resource could not be found." ] | |
xdr.send(options.data) | |
abort: -> xdr.abort() if xdr | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment