2

I am trying to write simple webpage that use js to get me some information stock prices. So, I am wondering if I can make an HTTP request from a localhost to a website. So far, I am getting a Access-Control-Allow-Origin error. and I wounder if the problem has to do with cross domain access or is it just because I am using a localhost?

<html>
<header>
</header>
<body>
    <p id="price"></p>
    <script>
        var url = "https://api.gemini.com/v1/pubticker/BTCUSD";

        var con = new XMLHttpRequest();
        con.open('GET', url, true);
        con.send();
        document.getElementById("price").innerHTML = con.responseText;
    </script>
</body>
</html>
Adam Rich
  • 86
  • 2
  • 10

2 Answers2

1

See if the solution mentioned here helps resolve your issue "No 'Access-Control-Allow-Origin' header is present on the requested resource"

Reference from above questions - https://www.html5rocks.com/en/tutorials/cors/

Nikitha
  • 11
  • 5
0

It is most likely because of cross domain request, (your domain is localhost in this case)

The host may decide how to react to your request (denied in this case)

In some other cases, it maybe because of the API needs some cookie/ session/ authenticate token which you don't have on the script

James Maa
  • 1,764
  • 10
  • 20