json “NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17340482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:54:09  来源:igfitidea点击:

"NS_ERROR_DOM_BAD_URI: Access to restricted URI denied"

javascriptajaxjsond3.jsjsonp

提问by Schnodderbalken

I have an html-file with several d3-graphs directly written in script tags into it. When I outsource one of the graphs into an external js file I get this message "NS_ERROR_DOM_BAD_URI: Access to restricted URI denied". If I delete the code with d3.json where it reads a local json file the error disappears. But it has to be possible to load a json file in an external js which is embedded into an html, right?

我有一个 html 文件,其中有几个 d3-graphs 直接用脚本标签写入其中。当我将其中一个图形外包到外部 js 文件中时,我收到此消息“NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝”。如果我删除带有 d3.json 读取本地 json 文件的代码,错误就会消失。但是必须可以在嵌入到 html 中的外部 js 中加载 json 文件,对吗?

d3.json("forcetree.json", function(json) {
root = json;
update();
});

回答by KJP

I was having the same error and the solution is to have your index.html, script.js and data.json in the same directory.

我遇到了同样的错误,解决方案是将 index.html、script.js 和 data.json 放在同一目录中。

回答by aftrix

Specify your .json file relative to your .html file root

指定相对于 .html 文件根的 .json 文件

Ex:

前任:

d3.json("js/forcetree.json", function(json) {
  root = json;
  update();
});

回答by TotPeRo

I have the same problem and i solve using the json file path like this:

我有同样的问题,我使用这样的 json 文件路径解决:

d3.json("file:///C:/path/...../js/forcetree.json", function(json) {
  root = json;
  update();
});

if i access this path from browser the file open the URL.

如果我从浏览器访问此路径,文件将打开 URL。

回答by giraffe.guru

I solved this issue by moving the JSON file to a subdirectory of the directory containing my html file.

我通过将 JSON 文件移动到包含我的 html 文件的目录的子目录解决了这个问题。

BROKEN:

破碎的:

www/
  code/
    hello.html    # refers to ../data/hello.json
  data/
    hello.json

WORKING:

在职的:

www/
  hello.html      # refers to data/hello.json
  data/
    hello.json