调用finance.yahoo api使用jquery [英] Calling finance.yahoo api using jquery
问题描述
我想发送http请求获取finance.yahoo股票数据与url喜欢: http://finance.yahoo.com/d/quotes.csv?s=GAIL.NS+BPCL.NS+%5ENSEI&f=snl1hgp 返回一个csv文件。我想读取响应数据,并使用Javascript或JQuery移动在列表视图中填充它。
我尝试使用以下代码:
code> $。ajax({
type:GET,
url:http://finance.yahoo.com/d/quotes.csv,
data: s = GAIL.NS + BPCL.NS +%5ENSEI& f = snl1hgp,
dataType:text / csv,
success:function(data){
alert(JSON.stringify ('data is:'+ data));
}
});
我得到空白数据作为警报。
任何示例代码或有用的链接将不胜感激。
我认为问题是请求是跨域。此处还有另一个问题:
还有另一个答案: Yahoo JSONP Ajax请求包含在回调函数中
href =http://stackoverflow.com/questions/14575323/displaying-ajax-results-from-yahoo-finance-using-underscore-js>使用underscore.js显示yahoo finance的ajax结果
这是一个工作的jsfiddle,它向d.yimg.com发送一个jsonp请求,以获取数据 http://jsfiddle.net/gp6zL/
YAHOO.Finance.SymbolSuggest.ssCallback = function(data){
alert(JSON.stringify(data));
};
var query;
query ='Google';
if(query.length> 0){
$ .ajax({
type:GET,
url:http: yimg.com/autoc.finance.yahoo.com/autoc,
data:{
query:query
},
dataType:jsonp,
jsonp :callback,
jsonpCallback:YAHOO.Finance.SymbolSuggest.ssCallback,
});
}
I want to send http request for fetching finance.yahoo stock data with url like : http://finance.yahoo.com/d/quotes.csv?s=GAIL.NS+BPCL.NS+%5ENSEI&f=snl1hgp which returns a csv file. I want to read the response data and fill it in a listview using Javascript or JQuery mobile. None of the links I referred helped me.
I tried using the following code:
$.ajax({
type: "GET",
url: "http://finance.yahoo.com/d/quotes.csv",
data: "s=GAIL.NS+BPCL.NS+%5ENSEI&f=snl1hgp",
dataType: "text/csv",
success: function(data) {
alert(JSON.stringify('data is :' + data));
}
});
I get blank data as alert. Any sample code or useful link would be appreciated.
I think that the problem is the request is cross domain. There is another question about this here:
and another answer here :Yahoo JSONP Ajax Request Wrapped in callback function
and a working example here: Displaying ajax results from yahoo finance using underscore.js
Here is a working jsfiddle which makes a jsonp request to d.yimg.com to get the data http://jsfiddle.net/gp6zL/
YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
alert(JSON.stringify(data));
};
var query;
query = 'Google';
if (query.length > 0) {
$.ajax({
type: "GET",
url: "http://d.yimg.com/autoc.finance.yahoo.com/autoc",
data: {
query: query
},
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
});
}
这篇关于调用finance.yahoo api使用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!