gpt4 book ai didi

json - 加载 JSON 文件时,请求的资源上不存在 'Access-Control-Allow-Origin' header 错误

转载 作者:行者123 更新时间:2023-12-04 12:54:22 27 4
gpt4 key购买 nike

我的数据集托管在我的保管箱帐户上,但不是调用它的 Javascript 文件。
我正在使用 D3 和 Polymaps 来可视化数据,但是我收到一条错误消息:“XMLHttpRequest 无法加载 https://www.dropbox.com/s/89adzt973quosda/solaruse.json。请求的资源上不存在“Access-Control-Allow-Origin” header 。Origin 'null' 是因此不允许访问。”
(保管箱文件的链接有效,因此您可以查看)

这是我用来加载 JSON 文件的代码(我正在本地开发站点)
从这一点上我不确定该怎么做。

var po = org.polymaps;
//Create map object, append to #map
var map = po.map()
.container(d3.select("#map").append("svg").node())
.zoom(4)
.add(po.interact());
// Add the CloudMade image tiles as a base layer…
map.add(po.image()
.url(po.url("http://{S}tile.cloudmade.com"
+ "/1a1b06b230af4efdbb989ea99e9841af" // http://cloudmade.com/register
+ "/998/256/{Z}/{X}/{Y}.png")
.hosts(["a.", "b.", "c.", ""])));
// Add the compass control on top.
map.add(po.compass()
.pan("none"));
// Add the custom locations/acres
d3.json("https://www.dropbox.com/s/89adzt973quosda/solaruse.json", function(data){
// Insert layer beneath the compass.
var layer = d3.select("#map svg").insert("svg:g", ".compass");
// Add an svg:g for each Name.
var marker = layer.selectAll("g")
.data(d3.entries(data))
.enter().append("svg:g")
.attr("transform", transform);
// Adding the circles
marker.append("svg:circle")
//function scraping the acres from the dataset
.attr()
});

最佳答案

问题

发生这种情况是因为 Dropbox 不允许通过其正常域进行跨源请求。见 the MDN CORS docs有关跨源请求的更多信息。

解决方案

您应该可以使用 Dropbox HTTP api (特别是 get file 资源)。或者,您可以使用 Dropbox JS api如果你想使用 JS 函数而不是 http 请求。

或者,正如您在评论中提到的,您可以通过托管自己的 JS 文件来简单地避免使用 Dropbox 😁

关于json - 加载 JSON 文件时,请求的资源上不存在 'Access-Control-Allow-Origin' header 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20361893/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com