【问题标题】:JSON BTC/LTC ticker is not working anymoreJSON BTC/LTC 代码不再工作
【发布时间】:2014-08-11 14:26:09
【问题描述】:

上个月我一直在使用这个 JSON 代码。它一直像魅力一样工作,但今天它停止了工作;也许有人知道这里出了什么问题?

$(function () {
    startRefresh();
});

function startRefresh() {
    setTimeout(startRefresh, 10000);
    var turl = 'https://btc-e.com/api/2/ltc_btc/ticker';
    $.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22' + encodeURIComponent(turl) + '%22&format=json', function (data) {
        jQuery('#ticker').html(data['query'].results.ticker.last);
        jQuery('#ticker').append(' BTC');
    });
}

http://jsfiddle.net/marcetin/9FHp3/4/

这是相同的示例,但使用 Cryptsy API 并且运行良好:

http://jsfiddle.net/marcetin/P2t9R/2/

【问题讨论】:

  • 哦,看,在您的控制台中...出现错误消息。
  • 是不是和jsonp有关? BTC-E 能否改变其 API 中的某些内容?

标签: javascript jquery html json bitcoin


【解决方案1】:

我检查了https://btc-e.com/api/2/ltc_btc/ticker 并返回了 JSON,所以问题不在于该网站。

我检查了您的代码,除了有点脏之外,没有什么可以阻止它提取该服务。

因此,问题似乎在雅虎一方。 Purhaps API 不再可通过 Yahoo 获得。

我已经清理(并评论了)你的代码:http://jsfiddle.net/9FHp3/27/

// Function for pulling JSON
function startRefresh() {
    // This is the API URL
    var turl = 'https://btc-e.com/api/2/ltc_btc/ticker';
    // This sends the API URL through Yahoo?
    $.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22' + encodeURIComponent(turl) + '%22&format=json', function (data) {
        // Writes to the page 
        $('#ticker').html(data['query'].results.ticker.last+' BTC');
    });
}
// Do the initial pull
startRefresh();
// Refresh every 10000
setInterval(startRefresh, 10000);

但是,您确实应该从服务器端代码(例如 PHP)中提取 REST API。除非它们在 JSONP 或 CORS 中可用,否则它们实际上并不适用于跨域客户端脚本。

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 2017-04-13
    • 2020-09-30
    • 1970-01-01
    相关资源
    最近更新 更多