mySQL DB: No 'Access-Control-Allow-Origin'


#1

When trying to post data from my html5 app (built in Phaser and using ajax (similar code: http://stackoverflow.com/questions/22515159/phaser-js-php-leaderboard) to my cloud 9 mySQL DB – I am receiving this message – XMLHttpRequest cannot load https://xxxxx-xxxxx/development/xxxxx/php/setScore.php. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://preview.c9users.io’ is therefore not allowed access.

I read on StackOverflow there was a bug that possibly was causing this issue but the same post said that bug was recently resolved. I would appreciate any guidance so I can continue the development.

Thanks.


#2

Hi,

Quick few questions:

  • Is your workspace private? Is your application url private too?
  • How are you trying to access the url that’s failing?

Regards,
​Mutahhir


#3

The work is private. I did tried to make it public but no luck.

Regarding application url – I assume this may be private – when I run the application it is https://preview.c9users.io/xxxx/pl-development-server/penny/index.html

Within the application, I am trying to access the php page with the following link:

submitScore: function (username, score) {

var data="username="+username+"&score="+score;

var request = new XMLHttpRequest();
request.open('POST', 'https://pl-development-server-xxxx.c9users.io/development/penny/php/setScore.php', true);
//request.open('POST', 'https://preview.c9users.io/xxxx/pl-development-server/penny/php/setScore.php', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.onload = function() {
  if (request.status >= 200 && request.status < 400){
    // Success!
    // here you could go to the leaderboard or restart your game .
  } else {
    // We reached our target server, but it returned an error

  }
};  
request.send(data);
},