【问题标题】:Fetching data from a cross-domain api从跨域 api 获取数据
【发布时间】:2017-09-29 06:20:58
【问题描述】:

谁能帮我从https://dexonline.ro/definitie/skate?format=json 获取数据。 我尝试了这样的 fetch/ajax,但我收到了这个错误:

使用邮递员它可以工作...... 另外我英语不好,所以写代码,提前谢谢

【问题讨论】:

标签: cors cross-domain fetch-api


【解决方案1】:

您好,我想您解决了您的问题,所以我为您提供了如何解决此限制的方法。 创建一个简单的文件 PHP 并复制/粘贴,我做 file_get_contents 你拿 json 然后你解析到一个 var javascript 你就完成了,问候;)。

 <?php
   $json = file_get_contents("https://dexonline.ro/definitie/skate?format=json");
?>
<!DOCTYPE html>
<html>
<head>
    <title>test</title>
</head>
<body>
<script>
    var json = <?php echo $json; ?>;
    document.body.onload = function(){
        document.write(json.word);//return Skate
    };
</script>
</body>
</html>

问候。

【讨论】:

  • 感谢您的帮助 ;)
猜你喜欢
  • 1970-01-01
  • 2012-09-23
  • 2012-10-07
  • 2019-06-21
  • 1970-01-01
  • 2016-06-21
  • 2018-02-21
  • 2013-08-05
  • 2021-02-27
相关资源
最近更新 更多