0

访问 coinbase API https://coinbase.com/api/doc/1.0/currencies/exchange_rates.html 就我而言,我有带有比特币字段和其他货币字段(美元、英镑、欧元等)的文本框。是

 <h6>BTC</h6>
 <input type="text" id ="coin"/>
 <div class="row">
    <h6>USD</h6>
    <input type="text" id='usd'/>
 </div>
 <div class="row">
    <h6>GBP</h6>
    <input type="text" id="gbp"/>
 </div>

javascript

$(document).ready(function () {
    $('#coin').keyup(function () {
        var url = 'https://coinbase.com/api/v1/currencies/exchange_rates?callback=?';
        $.getJSON(url, function (data) {
        });
    });
});

错误

语法错误:缺少;声明之前

{"vnd_to_usd":"4.7e-05","ars_to_btc":"0.00021","mmk_to_btc":"2.0e-06","ye..

我在这里做错了什么?

4

1 回答 1

-1

感谢您的评论,我解决了这个问题。

    $(document).ready(function () {
       $('#coin').keyup(function () {           
         var btc = $('#coin').val();
         $.ajax({
              url: "<?php echo site_url("buy/exchange_rates"); ?>",
              type: "POST",
              data: {
                 btc:btc
              },
              dataType: 'json',
              success: function (data, textStatus, xhr) {
                $('#usd').val(data.usd);
                $('#gbp').val(data.gbp);
              },
              async: false,
              error: function (xhr, textStatus, errorThrown) {
              }
           });
        }); 



 function exchange_rates()
    {
    $btc = $this->input->post('btc');
    if ($btc != "")
        {
        $data = json_decode(file_get_contents("https://coinbase.com/api/v1/currencies/exchange_rates"), 'TRUE');
        $usd = round($data['btc_to_usd']);
        $gbp = round($data['btc_to_gbp']);
        $obj = array();
        $obj['usd'] = $usd; 
        $obj['gbp'] = $gbp;  
        echo json_encode($obj);
        }
    }
于 2014-08-07T06:31:28.310 回答