getJSON回调不起作用

时间:2017-07-31 06:21:22

标签: javascript callback getjson

    <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>        
        <script>

        function getprice(){
            $.getJSON("https://api.bithumb.com/public/ticker?Callback=?", function(data) {
                var price = parseFloat(data['data']['closing_price'])
                $('#price').html( price);                  

                });              
          }

https://poloniex.com/public?command=returnTicker

poloniex的网址效果很好。但是bithumb不是。

1 个答案:

答案 0 :(得分:0)

如上所述它在标题中有拼写错误,你应该联系店主。同时,您可以使用YQL

执行代理请求

function getprice() {
  $.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20*%20FROM%20json%0AWHERE%20url%3D%22https%3A%2F%2Fapi.bithumb.com%2Fpublic%2Fticker%22&format=json&diagnostics=true&callback=", function(data) {
    //console.log(data)
    var price = parseFloat(data.query.results.json.data.closing_price)
    $('#price').html(price);
  });
}
getprice();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

price: <span id="price">...</span>