Calling finance.yahoo api using jquery

后端 未结 2 1663
一个人的身影
一个人的身影 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条回答
  •  北荒
    北荒 (楼主)
    2021-01-16 05:17

    I try to take jQuery out of the equation. The following code will work as long as you whitelist "finance.yahoo.com".

    var request = new XMLHttpRequest();
    request.open("GET", "http://finance.yahoo.com/d/quotes.csv?s=GAIL.NS+BPCL.NS+%5ENSEI&f=snl1hgp", true);
    request.onreadystatechange = function() {//Call a function when the state changes.
        if (request.readyState == 4) {
            if (request.status == 200 || request.status == 0) {
                console.log(request.responseText);
            }
        }
    }
    request.send();
    

提交回复
热议问题