How do I open a json file using javascript d3?

后端 未结 3 1759
醉酒成梦
醉酒成梦 2020-12-11 22:36

I\'m trying to extract elements from a JSON file using javascript, however I\'m getting an error saying it can not load the JSON file.

This is what my code looks lik

相关标签:
3条回答
  • 2020-12-11 23:01

    Alternatively to installing web server or using 3rd party online environments you can just use different code editor - Brackets. It offers feature called "Live Preview". I just hit same error Uncaught XMLHttpRequest with similar code, can confirm code works perfectly in Brackets.

    Brackets works directly with your browser to push code edits instantly, so your browser preview is always up to date while you're coding — no page reloads needed. In order to keep your current web browsing unaffected, Brackets Live Preview opens an additional copy of Chrome using a separate Chrome profile. // From How to Use Brackets

    0 讨论(0)
  • 2020-12-11 23:13

    Cross origin requests are only supported for HTTP.

    Load the site over HTTP. Install a web server (such as Apache HTTPD or Lighttpd) if you need to.

    0 讨论(0)
  • 2020-12-11 23:17

    d3.json is meant to load data through HTTP. As @Quentin said, you can set up a local server to serve the data over HTTP.

    For development like this I use firefox, it seems to be more permissive when it comes to local cross origin requests than chrome. Alternatively you can use http://tributary.io/

    Example with your code: http://tributary.io/inlet/5776228

    0 讨论(0)
提交回复
热议问题