I'm trying to access an API with a fetch request, On some website it works like a charm, but on some others I get this error, If I load the link from my browser it works...
Failed to load https://bittrex.com/api/v1.1/public/getticker?market=btc-usd:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://mydomaine.com' is therefore not allowed access. If an opaque
response serves your needs, set the request's mode to 'no-cors' to fetch the
resource with CORS disabled.
I'm lost, and I tried everything. I get the exact same thing if I write "no-cors" instead of "cors"
fetch(urlbittrexbtcusd,{ mode: "cors"})
.then(function(response) {
if(response.status == 200) { // Check if response went through
response.json().then(function(data) {
console.log(data);
bittrexbtcusdprice = parseFloat(data.result.last).toFixed(2);
});
} else { // Response wasn't ok. Check dev tools
console.log("response failed?");
console.log(response);
}
});
I've read this article, but can't figure out what it tries to achieve and how to plug my fetch to its code... https://www.html5rocks.com/en/tutorials/cors/ I don't understand what is "method" referring to, in his example.
I'm on an FTP and not on my server.