繁体   English   中英

尝试通过crunchbase API提取JSON数据。 我究竟做错了什么?

[英]Trying to pull JSON data via the crunchbase API. What am I doing wrong?

<html>
    <head>
        <title>Result</title>
        <link rel='stylesheet' type='text/css' href='stylesheet.css'/>

    </head>
    <body>
        <div></div>   
    <script>


     $(document).ready(function() {
     $.getJSON("http://api.crunchbase.com/v/1/company/facebook.js?api_key=mgxpds8ja7f6cncwd39caed7")
      });

    </script>
    </body>
</html>

我觉得有一些非常容易让我失踪,但我似乎无法取消任何数据。

代码中存在相同的原始策略违规,您需要传递一个额外的参数callback=? 这样它就会利用JSONP来发出请求。

$.getJSON("http://api.crunchbase.com/v/1/company/facebook.js?api_key=mgxpds8ja7f6cncwd39caed7&callback=?", function(data){
    console.log(data);
    //Do something with the data
})

演示: 小提琴

获取JSON后,下一步需要添加回调并对JSON数据执行一些操作,

$.getJSON("http://api.crunchbase.com/v/1/company/facebook.js?api_key=mgxpds8ja7f6cncwd39caed7", function(data){
       //CALLBACK
       console.log(data); //LIST DATAs
       //Do Something over here
})

http://api.jquery.com/jQuery.getJSON/

好。 我看到了几件事......

  1. 包括Jquery脚本标记。
  2. 将ID添加到要放置结果的位置。
  3. 改变下面提到的脚本..
  4. 使用API​​密钥检查设置,或者只需使用您的php后端检索JSON,然后将其放在您的页面上。 像这样使用JSON将返回跨域错误。

检查下面的HTML,就像一个魅力,但对于x域错误...

<html>
    <head>
        <title>Result</title>
        <link rel='stylesheet' type='text/css' href='stylesheet.css'/>

    </head>
    <body>
        <div id="results"></div>   
    <script>


     $(document).ready(function() {
     $("#results").html( function () {
     return $getJSON("http://api.crunchbase.com/v/1/company/facebook.js?api_key=mgxpds8ja7f6cncwd39caed7")
});      
});

    </script>
    </body>
</html>

谢谢!

@leo。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM