The Loader.headers object has a new property requestedWith. By default this is set to false, but it can be used to set the X-Requested-With header to XMLHttpRequest (or any other value you need). To enable this do this.load.headers.requestedWith = 'XMLHttpRequest' before adding anything to the Loader #2398

This commit is contained in:
Richard Davey 2016-07-20 12:45:11 +01:00
parent 60b8d78ab8
commit cff28860fa
2 changed files with 20 additions and 3 deletions

View file

@ -323,6 +323,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* BitmapData.shadow and BitmapData.text now both `return this` keeping them in-line with the docs (thanks @greeny #2634)
* Group.align has had its arguments changed so that it's now `(width, height, ...)` instead of `(rows, columns, ...)` (thanks @deargle #2643)
* Group.align now returns `true` if the Group was aligned, or `false` if not.
* The Loader.headers object has a new property `requestedWith`. By default this is set to `false`, but it can be used to set the `X-Requested-With` header to `XMLHttpRequest` (or any other value you need). To enable this do `this.load.headers.requestedWith = 'XMLHttpRequest'` before adding anything to the Loader.
### Bug Fixes

View file

@ -106,12 +106,23 @@ Phaser.Loader = function (game) {
* Used to map the application mime-types to to the Accept header in XHR requests.
* If you don't require these mappings, or they cause problems on your server, then
* remove them from the headers object and the XHR request will not try to use them.
*
* This object can also be used to set the `X-Requested-With` header to
* `XMLHttpRequest` (or any other value you need). To enable this do:
*
* `this.load.headers.requestedWith = 'XMLHttpRequest'`
*
* before adding anything to the Loader. The XHR loader will then call:
*
* `setRequestHeader('X-Requested-With', this.headers['requestedWith'])`
*
* @property {object} headers
* @default
*/
this.headers = {
json: "application/json",
xml: "application/xml"
"requestedWith": false,
"json": "application/json",
"xml": "application/xml"
};
/**
@ -2330,9 +2341,14 @@ Phaser.Loader.prototype = {
xhr.open("GET", url, true);
xhr.responseType = type;
if (this.headers['requestedWith'] !== false)
{
xhr.setRequestHeader('X-Requested-With', this.headers['requestedWith']);
}
if (this.headers[file.type])
{
xhr.setRequestHeader("Accept", this.headers[file.type]);
xhr.setRequestHeader('Accept', this.headers[file.type]);
}
onerror = onerror || this.fileError;