I am trying to retrieve data from a premium API on Quandl.com with the below JavaScript code, and display the results in my browser. Both the JS file and the HTML file are on my local computer, but the following problem appears also when incorporating the code on my webpage:
The first, public API URL (the one deactivated in the comment field) works fine and returns the expected data. The second, premium API URL leads to the following error in my Google Chrome console:
Access to XMLHttpRequest at 'https://www.quandl.com/api/v3/datatables/SHARADAR/SEP.json?ticker=AAPL&api_key=xxxxx' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
What is possibly causing this issue, and is there a way to change the javascript code to solve this problem?
JavaScript (quandldata.js):
/*! var url = "https://www.quandl.com/api/v3/datasets/CURRFX/JPYSEK.json" */
var url = "https://www.quandl.com/api/v3/datatables/SHARADAR/SEP.json?ticker=AAPL&api_key=xxxxxxxx"
function setup() {
noCanvas();
loadJSON(url, gotData);
}
function gotData(data) {
var quandl = data.dataset.data
createElement('h1', data.dataset.column_names);
for (var i = 0; i < 5; i++){
createP(quandl[i])
}
}
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>QuandlData</title>
<link href="quandldata.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.20/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.4.20/addons/p5.dom.min.js"></script>
<script src="quandldata.js"></script>
</body>
</html>