JSON BTC / LTC自动收录机不再工作了

时间:2014-03-18 21:40:00

标签: javascript jquery html json bitcoin

我上个月一直在使用这个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/

1 个答案:

答案 0 :(得分:1)

我检查了https://btc-e.com/api/2/ltc_btc/ticker并重新获得了JSON,因此问题不在于该网站。

我检查了你的代码,除了有点脏,没有任何东西可以阻止它提供这项服务。

所以,问题似乎出现在雅虎方面。也许通过雅虎不再提供API。

我已经清理(并评论过)了您的代码: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。除非它们在JSONPCORS中可用,否则它们并非真正用于跨域客户端脚本。

我希望这有帮助!