Interactive problems and JavaScript

Back to General discussions forum

Dmitry_Kovalov     2019-01-23 22:24:51
User avatar

Привет, Родион :)

For the task #176 I was trying to use JavaScript (don't ask me why JS :) code like this:

var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    console.log(this.responseText);
  }
};
xhttp.open("POST", "https://open-abbey.appspot.com/interactive/say-100", true);
xhttp.send("token: TOKEN");

But, because of this error, I wasn't able to do this:

Access to XMLHttpRequest at 'https://open-abbey.appspot.com/interactive/say-100' from origin 'https://www.codeabbey.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

So, my question is :) Could you please set the value of Access-Control-Allow-Origin to the proper meaning :)

Quandray     2019-01-24 07:55:53
User avatar

If you put that url in a web browser, does it work? It does for me. I can also access the page from a command prompt using
curl https://open-abbey.appspot.com/interactive/say-100

Rodion (admin)     2019-01-25 06:15:54
User avatar

Dmitry, Hi!

As I understand you are trying to run your JS in another web-page and your browser restricts you from accessing different domain?

We can add the header, but I'm not sure we really want it... Appengine server have certain limits and probably won't survive if some people will eventually carelessly publish page bombing it with hundred requests per second... I'm afraid we've lost our previous server due to something like this... :)

Perhaps some of the following options may work for your purposes:

  • enable cross-origin requests in your browser, e.g. google-chrome --disable-web-security :)
  • run your code from selenium or HttpUnit or something like this
  • embed your code in grease-monkey script running for the same appengine page

Could any of this help?

Dmitry_Kovalov     2019-01-25 21:58:05
User avatar

Hi, Admin! Thank you! I'll try and report about results :)

Dmitry_Kovalov     2019-01-28 22:51:52
User avatar

This addon for Chrome browser allows me to do what I want: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en

Thank you for your help!

Please login and solve 5 problems to be able to post at forum