@@ -1466,6 +1466,7 @@ Phaser.Loader.prototype = {
14661466 file . loaded = true ;
14671467
14681468 var loadNext = true ;
1469+ var _this = this
14691470
14701471 switch ( file . type )
14711472 {
@@ -1515,7 +1516,42 @@ Phaser.Loader.prototype = {
15151516 {
15161517 // Load the XML before carrying on with the next file
15171518 loadNext = false ;
1518- this . xhrLoad ( this . _fileIndex , this . baseURL + file . xmlURL , 'text' , 'xmlLoadComplete' , 'dataLoadError' ) ;
1519+
1520+ if ( this . useXDomainRequest && window . XDomainRequest )
1521+ {
1522+ this . _ajax = new window . XDomainRequest ( ) ;
1523+
1524+ // XDomainRequest has a few quirks. Occasionally it will abort requests
1525+ // A way to avoid this is to make sure ALL callbacks are set even if not used
1526+ // More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9
1527+ this . _ajax . timeout = 3000 ;
1528+
1529+ this . _ajax . onerror = function ( ) {
1530+ return _this . dataLoadError ( _this . _fileIndex ) ;
1531+ } ;
1532+
1533+ this . _ajax . ontimeout = function ( ) {
1534+ return _this . dataLoadError ( _this . _fileIndex ) ;
1535+ } ;
1536+
1537+ this . _ajax . onprogress = function ( ) { } ;
1538+
1539+ this . _ajax . onload = function ( ) {
1540+ return _this . xmlLoadComplete ( _this . _fileIndex ) ;
1541+ } ;
1542+
1543+ this . _ajax . open ( 'GET' , this . baseURL + file . xmlURL , true ) ;
1544+
1545+ // Note: The xdr.send() call is wrapped in a timeout to prevent an issue with the interface where some requests are lost
1546+ // if multiple XDomainRequests are being sent at the same time.
1547+ setTimeout ( function ( ) {
1548+ _this . _ajax . send ( ) ;
1549+ } , 0 ) ;
1550+ }
1551+ else
1552+ {
1553+ this . xhrLoad ( this . _fileIndex , this . baseURL + file . xmlURL , 'text' , 'xmlLoadComplete' , 'dataLoadError' ) ;
1554+ }
15191555 }
15201556 break ;
15211557
@@ -1690,14 +1726,25 @@ Phaser.Loader.prototype = {
16901726 * @param {number } index - The index of the file in the file queue that loaded.
16911727 */
16921728 xmlLoadComplete : function ( index ) {
1729+ var data ;
16931730
1694- if ( this . _xhr . responseType !== '' && this . _xhr . responseType !== 'text' )
1695- {
1731+ if ( this . _ajax && this . _ajax . responseText ) {
1732+ if ( this . _ajax . contentType !== '' && this . _ajax . contentType !== 'text/plain' )
1733+ {
16961734 console . warn ( 'Invalid XML Response Type' , this . _fileList [ index ] ) ;
1697- console . warn ( this . _xhr ) ;
1735+ console . warn ( this . _ajax ) ;
1736+ }
1737+ data = this . _ajax . responseText
1738+ }
1739+ else if ( this . _xhr && this . _xhr . responseText ) {
1740+ if ( this . _xhr . responseType !== '' && this . _xhr . responseType !== 'text' )
1741+ {
1742+ console . warn ( 'Invalid XML Response Type' , this . _fileList [ index ] ) ;
1743+ console . warn ( this . _xhr ) ;
1744+ }
1745+ data = this . _xhr . responseText ;
16981746 }
16991747
1700- var data = this . _xhr . responseText ;
17011748 var xml ;
17021749
17031750 try
0 commit comments