三生石@ 2017-01-20 10:54 采纳率: 100%
浏览 50

JSON调用网址以获取数据

I am having problem while fetching data from the site, I want its dat to my site http://www.cvedetails.com/vulnerability-feeds-form.php

Here is the code `

<!DOCTYPE html>
<html>
<head>
    <title>json data</title>
</head>
<body>
<div class="demo" id="demo">
    <!-- <iframe src="http://www.cvedetails.com/widget.php?numrows=10&vendor_id=0&product_id=0&version_id=0&hasexp=0&opec=0&opov=0&opcsrf=0&opfileinc=0&opgpriv=0&opsqli=0&opxss=0&opdirt=0&opmemc=0&ophttprs=0&opbyp=0&opginf=0&opdos=0&orderby=1&cvssscoremin=10" width="100%" height="300px"></iframe> -->
</div>
<div class="demo2" id="demo2"><p></p></div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){
var FEED_URL='http://www.cvedetails.com/json-feed.php?numrows=10&vendor_id=0&product_id=0&version_id=0&hasexp=0&opec=0&opov=0&opcsrf=0&opfileinc=0&opgpriv=0&opsqli=0&opxss=0&opdirt=0&opmemc=0&ophttprs=0&opbyp=0&opginf=0&opdos=0&orderby=1&cvssscoremin=10';

$.ajax({
  url      :  FEED_URL + encodeURIComponent(FEED_URL),
  dataType : 'json',
  success  : function (data) {
    if (data.responseData.feed && data.responseData.feed.entries) {
      $.each(data.responseData.feed.entries, function (i, e) {
        header('Access-Control-Allow-Origin: http://www.cvedetails.com');
        alert('e.title');
        $('#demo2').append($('<p/>').text(e.title));

        console.log("------------------------");
        console.log("title      : " + e.title);
        console.log("author     : " + e.author);
        console.log("description: " + e.description);
      });
    }
  }
});
});
</script>
</body>
</html>

`

enter image description here

  • 写回答

1条回答 默认 最新

  • larry*wei 2017-01-20 23:52
    关注

    Looks like that site doesn't support CORS since they don't set the appropriate Access-Control-Allow-Origin. Since you can't fix this client side (outside of hacks), best is to set up a proxy server that can proxy the calls to that API. The proxy server can be on your own domain or you can specify the your own CORS response headers. You could also look into JSONP.

    A guide on CORS: https://www.moesif.com/blog/technical/cors/Authoritative-Guide-to-CORS-Cross-Origin-Resource-Sharing-for-REST-APIs/

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题