0

My index.html has this code to select the better destination server to connect:

<html>
  <head>
    <title>InterSite Sistemas Ltda - SITESAT</title>
    <script language="JavaScript" src="https://localhost/js/functions.js"></script>
  </head>
  <body onload="loginLoadBalancer('https://localhost/webservicelb')">
    Loading...
  </body>
</html>

And the functions.js has this code:

function loginLoadBalancer(url) {
  var req = new XMLHttpRequest();
  req.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
      window.location.replace(this.responseText);
    }
  };
  req.open("GET", url, true);
  req.send(null);
}

The webservicelb looks for the better server and returns the URL to redirect.

When I call https://localhost/ all works fine. But, if I use http://localhost/, JS doesn't run, the index.html freezes in "Loading...". Is there some way to allow JS to process https requests from a http page?

  • Do you have any console error? also server side – Greedo Jan 30 '20 at 16:12
  • See the [linked question](https://stackoverflow.com/questions/20035101/)'s answers. `http://localhost` and `https://localhost` are different origins, which means that your `XMLHttpRequest` running on a page loaded from `http://localhost` is trying to do a cross-origin request to `https://localhost`. Unless you have implemented CORS headers in the response, that cross-origin request will be blocked by the browser's Same Origin Policy. (Note that it's the origin of the page the code is running in, not the origin of the `.js` file, that matters.) – T.J. Crowder Jan 30 '20 at 16:16

0 Answers0