Forum General Unable to Load on Browser "Access-Control-Allow-Origin"

Discussion and help relating to the PlayerIO JavaScript SDK

Unable to Load on Browser "Access-Control-Allow-Origin"

Postby Aram Sargsyan » July 23rd, 2018, 6:25 pm

Hi,
I'm trying to make Ajax request to load JSON file stored in the GameFS.
I'm getting Access-Control-Allow-Origin error because response doesn't container specific CORS headers.

Can you say is there any settings in PlayerIO to enable CORS headers for responses ?

Thanks in advance.
Aram Sargsyan
Paid Member
 
Posts: 21
Joined: March 25th, 2018, 5:01 pm

Re: Unable to Load on Browser "Access-Control-Allow-Origin"

Postby Henrik » July 24th, 2018, 12:21 pm

Hey Aram,

I thought we had enabled this for files in GameFS?

What URL specifically are you trying to load in your game?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Unable to Load on Browser "Access-Control-Allow-Origin"

Postby Aram Sargsyan » July 24th, 2018, 12:55 pm

Hi Henrik,

The url is Generated by PlayerIO (gameFS.getUrl function).
Check out the Attached ScreenShot for the issue and url.

Thank you.
Attachments
Screen Shot 2018-07-23 at 3.29.18 PM.png
Screen Shot 2018-07-23 at 3.29.18 PM.png (52.51 KiB) Viewed 27472 times
Aram Sargsyan
Paid Member
 
Posts: 21
Joined: March 25th, 2018, 5:01 pm

Re: Unable to Load on Browser "Access-Control-Allow-Origin"

Postby Aram Sargsyan » July 24th, 2018, 1:08 pm

Also We have tried to load a json file from other domain, and it worked
Aram Sargsyan
Paid Member
 
Posts: 21
Joined: March 25th, 2018, 5:01 pm

Re: Unable to Load on Browser "Access-Control-Allow-Origin"

Postby Henrik » July 25th, 2018, 3:35 pm

Hey,

I did some digging, and it is enabled, but:

The origin server only sends out Access-Control-Allow-Origin headers if they get a request with the Origin header, and the CDN server in turn caches whatever headers it received on the first request.

This means that if you just try out the URL in a browser normally, it will not send the Origin header, and any subsequent requests will therefore not get the CORS headers in the response, even if you send the Origin header.

But, if the first request to a file contains the Origin header, the CORS headers should be cached and "stick" in the CDN for every subsequent request.

So, the easiest solution is to update the file in GameFS, and then load it in your game with an ajax request.

If you haven't made any changes to the file, you can just click the "rollback to this version" on the latest version, and it will make a copy and roll the version number, which will create a new file that hasn't been cached by the CDN yet.,
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Unable to Load on Browser "Access-Control-Allow-Origin"

Postby Aram Sargsyan » July 26th, 2018, 7:44 am

Thank You Henrik! Rollback soled the issue.
Aram Sargsyan
Paid Member
 
Posts: 21
Joined: March 25th, 2018, 5:01 pm


Return to General



cron