我正在尝试从 Yahoo's Finance API 获取 JSON 数据。
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback", function(data) {
// I am parsing JSON string using data here
});
问题是当股票收盘时,我需要显示最后交易值。我找到了一个将值作为 CSV 文件返回的链接。所以我需要下载它并用jQuery解析它。
这是我到目前为止所做的:
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D%27WRC%27&format=json&diagnostics=true&env=store://datatables.org/alltableswithkeys&callback", function(data) {
if(data.query.results.quote.DaysLow == null && data.query.results.quote.DaysHigh == null){
//When stock is closed this section works
var date = data.query.results.quote.LastTradeDate;
var datesplit = date.split('/');
$.ajax({
type: "GET",
url: "http://ichart.finance.yahoo.com/table.csv?s=WRC&a="+ datesplit[1] +"&b="+ datesplit[0] + "&c="+ datesplit[2] +"&d="+ datesplit[1] +"&e="+ datesplit[0] +"&f="+ datesplit[2] +"&g=d&ignore=.csv",
dataType: "text",
success: function(data) {
console.log(data);
}
});
}
else{
//When stock is not closed this section works
//There is no problem in this section
}
});
这是我收到的错误消息:
XMLHttpRequest 无法加载 http://ichart.finance.yahoo.com/table.csv?s=WRC&a=18&b=9&c=2012&d=18&e=9&f=2012&g=d&ignore=.csv。Access-Control-Allow-Origin 不允许 Origin null。
你能帮我下载CSV文件吗?