problem loading local json file with d3.json in Chrome

5,451 views
Skip to first unread message

Diana

unread,
Mar 15, 2012, 7:38:17 PM3/15/12
to d3-js
I got this message: XMLHttpRequest cannot load file: ,,
when using d3.json() to open a local file, actually I am trying to run
example bullet. Then I read in d3 document, found the information I
need:
******************************************
Note: Chrome has strict permissions for reading files out of the local
file system. Some examples use AJAX which works differently via HTTP
instead of local files. For the best experience, load the D3 examples
from your own machine via HTTP. Any static file web server will work;
for example you can run Python's built-in server:

python -m SimpleHTTPServer 8888
Once this is running, go to: http://localhost:8888/examples/
***************************************

I ran python start a server, no problem. My question is: if the
bullet.html is in Mac Users/foo/bullet.html. What should I put after
http://localhost:8888/?

Thanks
Diana

Miles McCrocklin

unread,
Mar 15, 2012, 7:57:58 PM3/15/12
to d3...@googlegroups.com
Diana, 

Based off of what I can gather, it's likely that you ran:

python -m SimpleHTTPServer 8888 

upon opening the terminal. I would recommend if you choose to develop this way, when you open the terminal do:

cd PATH/TO/PROJECT/bullet.html
python -m SimpleHTTPServer 8888

then when you go to your web browser do:

You could also create a file called index.html instead of bullet.html, this would allow you to just go to http://localhost:8888/ when opening your browser rather than http://localhost:8888/FILENAME.EXTENSION.

There are some other sources for developing and diving into d3. I recommend going through: http://bost.ocks.org/mike/d3/workshop/ in order to get 
1) an understanding of d3 before jumping into the tutorial 
2) how to develop using google chromes developer tools.

The way you're going about it seems fine for now though (and is how I started when going through that tutorial).

Cheers,

Miles

Diana

unread,
Mar 15, 2012, 8:22:16 PM3/15/12
to d3-js
Hi Miles,

Thank you very much for your quick response. It works when I cd to the
directory where bullet.html is. But I have to put d3.v2.js and all the
other files in the same directory.

This is the first time I use d3.json when developing in chrome. I
used it with Firefox before, it ran fine.

Thanks
Diana
On Mar 15, 4:57 pm, Miles McCrocklin <miles.mccrock...@gmail.com>
wrote:
> Diana,
>
> Based off of what I can gather, it's likely that you ran:
>
> python -m SimpleHTTPServer 8888
>
> upon opening the terminal. I would recommend if you choose to develop this
> way, when you open the terminal do:
>
> cd PATH/TO/PROJECT/bullet.html
> python -m SimpleHTTPServer 8888
>
> then when you go to your web browser do:http://localhost:8888/bullet.html.
>
> You could also create a file called index.html instead of bullet.html, this
> would allow you to just go tohttp://localhost:8888/when opening your
> browser rather thanhttp://localhost:8888/FILENAME.EXTENSION.
>
> There are some other sources for developing and diving into d3. I recommend
> going through:http://bost.ocks.org/mike/d3/workshop/in order to get
Reply all
Reply to author
Forward
0 new messages