I'm trying to parse the Coinbase API to pull back the current price of Bitcoin. Here is my code:
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.
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.