weixin_33744141 2017-11-11 12:21 采纳率: 0%
浏览 39

JSON API获取请求错误

The following is my code:

$(document).ready(function(){
        $.ajax({
            url: 'https://bitconnect.co/api/info/BTC_BCC',
            type: 'get',
            dataType: 'json',
            success: function(data){
                alert(data);
            },
            error: function(error){
                alert(error);
            }
        });
    });
<html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
            <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
            <script src = "//code.jquery.com/jquery-1.12.4.js"></script>
    
            <script src="try.js"></script>
        </head>
        <body>
            
        </body>
    </html>

I want to get the information from the url mentioned in the url section of ajax. But I'm getting the following error :

Failed to load https://bitconnect.co/api/info/BTC_BCC: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

I'm completely new to this section and have no idea of what the error is. It would be great if I could get any kind of help. Thanks in advance.

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33682719 2017-11-11 12:37
    关注

    You can do this in this way if you are doing it from localhost and using the proxy server of this app , or you can also self host and create a proxy server by following this url https://github.com/Rob--W/cors-anywhere/

    var proxyUrl = 'https://cors-anywhere.herokuapp.com/'
    
    $.ajax({
        url: proxyUrl+'https://bitconnect.co/api/info/BTC_BCC',
        type: 'get',
        dataType: 'json',
        crossDomain: true,
        headers: { "Access-Control-Allow-Origin": "*" },
    }).done(function(data) {
        console.log(data);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug