从跨域api获取数据

时间:2017-09-28 21:29:33

标签: cors cross-domain fetch-api

任何人都可以帮我从https://dexonline.ro/definitie/skate?format=json获取数据。 我尝试了这样的fetch / ajax,但是我收到了这个错误:

enter image description here

邮差有效...... 我也很擅长英语,所以只需编写代码,提前谢谢

1 个答案:

答案 0 :(得分:0)

嗨,我猜你解决了你的问题,所以我给你如何解决这个限制的方法。 创建一个简单的文件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>

问候。