Loader now uses XDomainRequest in IE9 to load JSON data to help with CORS issues.

This commit is contained in:
photonstorm 2014-04-29 14:41:26 +01:00
parent 9135b05ff7
commit 75a848f0ef
2 changed files with 51 additions and 6 deletions

View file

@ -81,6 +81,7 @@ Version 2.0.4 - "Mos Shirare" - 29th April 2014
* Tilemap.addTilesetImage will now raise a console.warn if you specify an invalid tileset key and not create the tileset rather than pick the default set.
* Math.smoothstep and Math.smootherstep have been updated to work regardless if a is > or < b (thanks @gre, fix #772)
* Text.updateText now sets the lineCap to `round` to avoid occassional font glitching issues in Chrome.
* Loader now uses XDomainRequest in IE9 to load JSON data to help with CORS issues.
### New Features

View file

@ -47,6 +47,12 @@ Phaser.Loader = function (game) {
*/
this._xhr = new XMLHttpRequest();
/**
* @property {XDomainRequest} - An ajax request used specifically by IE9 for CORs loading issues.
* @private
*/
this._ajax = null;
/**
* @property {boolean} isLoading - True if the Loader is in the process of loading the queue.
* @default
@ -963,12 +969,50 @@ Phaser.Loader.prototype = {
break;
case 'json':
this._xhr.open("GET", this.baseURL + file.url, true);
this._xhr.responseType = "text";
this._xhr.onload = function () {
return _this.jsonLoadComplete(_this._fileIndex);
};
this._xhr.send();
if (window.XDomainRequest)
{
this._ajax = new window.XDomainRequest();
// XDomainRequest has a few querks. Occasionally it will abort requests
// A way to avoid this is to make sure ALL callbacks are set even if not used
// More info here: http://stackoverflow.com/questions/15786966/xdomainrequest-aborts-post-on-ie-9
this._ajax.timeout = 3000;
this._ajax.onerror = function () {
return _this.dataLoadError(_this._fileIndex);
};
this._ajax.ontimeout = function () {
return _this.dataLoadError(_this._fileIndex);
};
this._ajax.onprogress = function() {};
this._ajax.onload = function(){
return _this.jsonLoadComplete(_this._fileIndex);
};
this._ajax.open('GET', this.baseURL + file.url, true);
this._ajax.send();
}
else
{
this._xhr.open("GET", this.baseURL + file.url, true);
this._xhr.responseType = "text";
this._xhr.onload = function () {
return _this.jsonLoadComplete(_this._fileIndex);
};
this._xhr.onerror = function () {
return _this.dataLoadError(_this._fileIndex);
};
this._xhr.send();
}
break;
case 'tilemap':