Calling finance.yahoo api using jquery

后端 未结 2 1666
一个人的身影
一个人的身影 2021-01-16 04:43

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

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-16 05:25

    I think that the problem is the request is cross domain. There is another question about this here:

    Cross-Domain get CSV file

    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",
            });
        }
    

提交回复
热议问题