Question

I have been using this JSON ticker for the last month. It has been working like a charm, but today it stopped working; maybe anyone knows what could have gone wrong here?

$(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/

Here is the same example but with Cryptsy API and works well:

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

Was it helpful?

Solution

I checked out https://btc-e.com/api/2/ltc_btc/ticker and got JSON back, so the issue is not with that site.

I checked out your code, and aside from being a little dirty, there was nothing that would keep it from pulling that service.

So, the issue seems to be at Yahoo's side. Purhaps that API is no longer available through Yahoo.

I have have cleaned up (and commented) your code: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);

However, you should really be pulling REST APIs from a server-side code such as PHP. Unless they are available in JSONP or CORS they are not really intended for cross-domain client-side script.

I hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top