我得到了" No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' null'因此不允许访问。"

时间:2016-09-19 05:52:47

标签: javascript jquery html ajax api

我做了一些javascript来从api获取对象。现在错误显示我没有访问控制?我该怎么办?

<script type="text/javascript">
    function getLatest(){
      var data = {};
      $.ajax({
          url: 'http://api.rappler.com/index.php?option=com_rappler&task=mobileapi.getarticlelist&limit=5&catid=23',
          data: data
        });
      console.log(data);
    }
</script>

1 个答案:

答案 0 :(得分:0)

Try this one:

<script type="text/javascript">
    function getLatest(){
      var data = {};
      $.ajax({
          url: 'http://api.rappler.com/index.php?option=com_rappler&task=mobileapi.getarticlelist&limit=5&catid=23',
          data: data,
          async:true,
          dataType : 'jsonp',   //you may use jsonp for cross origin request
          crossDomain:true
        });
      console.log(data);
    }
    getLatest();
</script>