I've seen other questions about this, but after two hours of trying different things, I still haven't made it work.
Originally, in my website's JS file, I had this:
jQuery.getJSON("https://www.quandl.com/api/v3/datasets/WIKI/FB.json?rows=1&api_key=rzH6xM9oAF1phUUPKxoo", function(data1){
stocksFB = data1.dataset.data[0][1];
});
In my window.onload, I have:
document.getElementById("stock_area").innerHTML = stocksFB;
However, most of the time the text would show undefined. A few times, it would show the correct information. Thus, after a little research I thought I needed a callback function.
I tried a few different things:
var getStocks = function(){
//the same query from above here
};
and:
function getStocks(){
getStocksCallback();
};
function getStocksCallback(){
//the same query from above
};
also:
function getStocks(function(){
//the same query from above
});
and then an extra getStocks()
in the onload function for the latter two.
However, the results were always still undefined. Could anyone give me a hint (I'm new to this)?