1

I'm trying to parse the Coinbase API to pull back the current price of Bitcoin. Here is my code:

http://jsfiddle.net/9Kx5N/20/

var mtgoxAPI = "https://coinbase.com/api/v1/prices/spot_rate";
$.getJSON(mtgoxAPI, function (json) {
      // Set the variables from the results array
      var price = json.amount;
      // Set the table td text
      $('#btc-price').text(price);
});

Any help would be appreciated.

Visruth
  • 3,430
  • 35
  • 48
  • 1
    Where is the "parsing"? It's done by jQuery automatically, so what I'm really asking is *what* is the problem? (Because it's not "parsing") - The error probably lies in failed access, such as "XMLHttpRequest cannot load ... No 'Access-Control-Allow-Origin' header is present on the requested resource" or other network/unexpected response issue. – user2864740 Mar 02 '14 at 04:45

1 Answers1

3

Try using jsonp to sidestep the origin nonsense:

var mtgoxAPI = "https://coinbase.com/api/v1/prices/spot_rate?callback=?";

$.getJSON(mtgoxAPI, null, function (json) {

    // Set the variables from the results array
    var price = json.amount;


    // Set the table td text
    $('#btc-price').text(price);

});

works! The coinbase API supports jsonp and jQuery can tell that you want jsonp when it sees

"?callback=?"

at the end of the URL.

Community
  • 1
  • 1
Tom McClure
  • 6,699
  • 1
  • 21
  • 21