From 565e7cd097cf0aabb8bae8ad7c84d470b2ff906e Mon Sep 17 00:00:00 2001 From: Hasse Feldthaus Date: Wed, 29 Jul 2015 17:16:19 +0200 Subject: [PATCH] Added XDomainRequest as fallback method for ajax, if XMLHttpRequest fails. --- src/openseadragon.js | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 64349972..0d2c894c 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -2045,8 +2045,40 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){ request.onreadystatechange = function(){}; - if ( $.isFunction( onError ) ) { - onError( request, e ); + if (window.XDomainRequest) { // IE9 or IE8 might as well try to use XDomainRequest + var xdr = new XDomainRequest(); + if (xdr) { + xdr.onload = function (e) { + if ( $.isFunction( onSuccess ) ) { + onSuccess({ // Faking an xhr object + responseText: xdr.responseText, + status: 200, // XDomainRequest doesn't support status codes, so we just fake one! :/ + statusText: 'OK' + }); + } + } + xdr.onerror = function (e) { + if ( $.isFunction ( onError ) ) { + onError({ // Faking an xhr object + responseText: xdr.responseText, + status: 444, // 444 No Response + statusText: 'An error happened. Due to an XDomainRequest deficiency we can not extract any information about this error. Upgrade your browser.' + }); + } + } + try { + xdr.open('GET', url); + xdr.send(); + } catch (e) { + if ( $.isFunction( onError ) ) { + onError( request, e ); + } + } + } + } else { + if ( $.isFunction( onError ) ) { + onError( request, e ); + } } } },