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>
0

2 Answers 2

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/

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Yes, it cross domain request problem. What I did was install a pluging to chrome to enable CORS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.