29

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?

d3.json("forcetree.json", function(json) {
root = json;
update();
});
Schnodderbalken
  • 3,257
  • 4
  • 34
  • 60
  • http://stackoverflow.com/questions/1105055/ajax-and-ns-error-dom-bad-uri-error – Adam Pearce Jun 27 '13 at 14:39
  • yeah but this is not a crossdomain json access right? the json file is located on my hard-drive plus I don't use the jquery or js json function however what I use is the json function from d3 which does not have something like jsonp – Schnodderbalken Jun 28 '13 at 12:36
  • http://stackoverflow.com/questions/17077931/d3-samples-in-a-microsoft-stack?answertab=active#tab-top – Adam Pearce Jun 28 '13 at 13:55
  • Are you running from a localhost or something? – Miguel Alejandro Fuentes Lopez Dec 27 '14 at 13:47
  • I found this error, trying to send bad name header. On an ajax request sending "Auhtorization" (bad typing) i found the NS_ERROR_DOM_BAD_URI (on firefox). After fix the header name for "Authorization", error disappears. Hope helps somebody. – danipenaperez Dec 15 '20 at 10:15
  • I got same error while trying to make a request from front-end. In my case reason was that I forgot to run my back-end server. – yokus Nov 06 '22 at 20:30

5 Answers5

22

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

KJP
  • 531
  • 2
  • 9
  • 19
  • 6
    @OP: strange that this answer was accepted. From your question, it looks like your data.json *is* in the same directory. No? – LarsH Jul 15 '14 at 19:44
6

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

Ex:

d3.json("js/forcetree.json", function(json) {
  root = json;
  update();
});
aftrix
  • 71
  • 1
  • 2
1

"NS_ERROR_DOM_BAD_URI: Access to restricted URI denied" error can come in multiple scenerio.

  1. When Requested resource is not found and having some issue with path reference.
  2. I was facing an issue with API calls, when calling an API. In this case we need to check the option calls of an API, sometime API is returning this error because of request is getting blocked at API gateway level.

In my case, API was returning this error due to apigee gateway is not able to authenticate the api calls and returining the 401 Bad Request.

sharad jain
  • 1,471
  • 13
  • 9
0

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

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

if I access this path from the browser the file opens.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
TotPeRo
  • 6,561
  • 4
  • 47
  • 60
  • 1
    How would that work on a remote client?!? You can't load a `file:...` except on your own computer?!? – Alexis Wilke Dec 17 '20 at 21:58
  • 1
    Read the question. This error tou get if you try to load from local computer. If you whant to load json from remote you need to use ajax call and the json file need to be hosted on web server. – TotPeRo Oct 27 '21 at 18:53
0

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

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
giraffe.guru
  • 480
  • 8
  • 21