I've gotten the code below working to pull the lastPrice
from the JSON data from Yahoo for a certain strike price, but only if I replace url
with an actual JSON file. Each time I use the actual URL instead of the file I get a "No 'Access-Control-Allow-Origin' header is present on the requested resource." warning. Is there anything that I'm doing wrong?
$.ajax({
url: 'https://query1.finance.yahoo.com/v7/finance/options/CL',
dataType: 'json',
type: 'get',
cache: false,
success: function(data) {
var jsonStr = JSON.stringify(data);
document.body.innerHTML = jsonStr;
$(data.optionChain.result[0].options[0].calls).each(function(index, value) {
if (value.strike == 85) {
var test = value.lastPrice;
console.log(test);
}
});
}
});