yahoo.finance.xchange - 不工作?

时间:2016-10-06 08:44:46

标签: jquery json api yahoo

我对xchange服务的请求有问题。 看看我的要求

var currency_from = "USD";
var currency_to = "INR";

var yql_base_url = "http://query.yahooapis.com/v1/public/yql";
var yql_query = 'select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20("'
        + currency_from + currency_to + '")';
var yql_query_url = yql_base_url
        + "?q="
        + yql_query
        + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
// console.log("conversion url : " + yql_query_url);
$.ajax({
    type : "GET",
    url : yql_query_url,
    async : false,
    success : function(result) {
        var name = result.query.results.rate.Name;
        var rate = parseFloat(result.query.results.rate.Rate, 10);
        // console.log("default rate : " + rate + " : name :" + name);
        defaultCurrency = rate;
        // $("#defaultCurrency-span").attr("default-currency-value", rate);
    }

错误时 - 我得到了下一个回复:({"错误":{" lang":" zh-CN","说明&# 34;:"没有找到表yahoo.finance.xchange"}}的定义。

你能帮助我并提出如何解决这个问题的建议吗?

提前谢谢。

1 个答案:

答案 0 :(得分:0)

谢谢大家。问题解决了。在这里。

`

var currencyExchangeRateurl = "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"
            + from
            + to
            + "%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json";
    $.ajax({
        type : "GET",
        url : currencyExchangeRateurl,
        success : function(data) {
//          console.log("SUCCESS : " + JSON.stringify(data));
            var name = data.query.results.row.name;
            var rate = parseFloat(data.query.results.row.rate, 10);
//          console.log("rate : " + rate + " : name :" + name);
        },
        error: function (response) {
            var r = JSON.stringify(response.responseText);
            localStorage.setItem("rvalue",r);
            errorFunctionTimeout();
        }
    });

`