问题
I've tried various approaches, the current is as follows
$(document).ready(function(){
$('#stage').click(function(){
jQuery.getJSON('https://mtgox.com/api/1/BTCUSD/ticker?callback=showTick',function(ticker){
$('div#tickerbox').html(ticker)}
)})})
Losing my mind . . .
回答1:
I built php tools to make this easy , providing pure text tickers, html tickers, and even image ticker( and other tools like rss ticker feeds ).
have a look at the code on : https://github.com/neofutur/bitcoin_simple_php_tools
more details and examples on : https://bitcointalk.org/index.php?topic=68205
the tools are including a 30 seconds caching system so you wont hit the api too often and thus avoid being blackisted by the anti-ddos system
I dont think javascript is the best idea to add a mtgox ticker, but if you really want it to be js, theres at least one javascript implementation, which is the firefox addon for those tickers : https://github.com/joric/mtgox-ticker https://github.com/joric/mtgox-ticker/blob/master/lib/main.js
also, know that SE also have a dedicated space for bitcoin related questions : http://bitcoin.stackexchange.com you could perhaps have had more answers here, where all bitcoiners are ;)
回答2:
Unfortunately, the Mt. Gox API does not support JSONP nor CORS at the time of this writing. It seems like it would be easy enough for them to add JSONP support, so if they add it in the near future, this answer should help; until then, however, this answer does not help. The rest of this answer assumes now is the future and they support JSONP.
First of all, you'll want to change callback=showTick
to callback=?
so jQuery knows to put its autogenerated callback name there. Then when your callback is called, ticker
will be a decoded JSON object, not a string, so you'll want to pull the information you want out of there. For example, to show the average price:
jQuery.getJSON('https://mtgox.com/api/1/BTCUSD/ticker?callback=?', function(data) {
// We can't use .return because return is a JavaScript keyword.
alert(data['return'].avg.display_short);
});
来源:https://stackoverflow.com/questions/12189296/how-do-i-add-mtgox-ticker-data-to-a-website