Loader xhrLoad to include headers? #2485

stoneman1 opened this Issue May 19, 2016 · 3 comments


None yet

2 participants


This Issue is about

  • A bug in the API

If you do this.game.load.json(key, url, overwrite). The server should know that you are actually requesting json. Otherwise the server might send you xml (which is default for many servers).

That happened to me and setting the request header for accept to application/json fixed this. But right now there is no request headers set which is not a good thing.

This is very hacky, but did not have the time to figure out better way to set them so here is my solution for it right now :

        var xhr = new XMLHttpRequest();
        xhr.open("GET", url, true);
        xhr.responseType = type;
        if (type === 'json') {
            xhr.setRequestHeader("Accept", "application/json");
            xhr.responseType = 'text';

So now I am asking if we should add those headers to the loader and then I might just do a PR with better solution, but not going to do it before asking if this is something people want.


This has come up a couple of times (not many, but a couple) so I think it's worth doing. So if you've time for a PR then please go ahead. The way I think I would like to do it, would be to have a public 'headers' property Object in the Loader, which has the file type (json) mapping to the header. It can be populated with default values, but making it public allows it to be over-ridden on a per-case basis.


I think I did it as you wished, but not sure :) Check this out #2585


Thanks for submitting this issue. We have fixed this, and the fix has been pushed to the dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment