最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 404 Error while trying access JSON file using D3 Framework - Stack Overflow

programmeradmin2浏览0评论

Hi so i'm in the middle of learning the D3 Framework, but no matter what I do, I can't seem to load my Json file. I'm running the script on a server and the JSON file is in the same directory as the html/d3 file im running it from but it keeps giving me a 404 error when I look at the console.

So Im running it on www.mywebsite, and then I have the Json file stored in www.mywebsite/mydata.json
Can anyone help me out?

<script src=".v3.min.js" charset="utf-8"></script> 
</head>
<body>
    <script type="text/javascript">

    d3.json("mydata.json", function(data){ 

        var canvas= d3.select("body").append("svg")
        .attr("width",500)
        .attr("height", 500)

        canvas.selectAll("rect")
            .data(data)
            .enter()
                .append("rect")
                .attr("width", function(d){ return d.age *10;})
                .attr("height", 50)
                .attr("y", function(d ,i){ return i* 50; })
                .attr("fill", "blue");
    });

    </script>

Hi so i'm in the middle of learning the D3 Framework, but no matter what I do, I can't seem to load my Json file. I'm running the script on a server and the JSON file is in the same directory as the html/d3 file im running it from but it keeps giving me a 404 error when I look at the console.

So Im running it on www.mywebsite., and then I have the Json file stored in www.mywebsite./mydata.json
Can anyone help me out?

<script src="http://d3js/d3.v3.min.js" charset="utf-8"></script> 
</head>
<body>
    <script type="text/javascript">

    d3.json("mydata.json", function(data){ 

        var canvas= d3.select("body").append("svg")
        .attr("width",500)
        .attr("height", 500)

        canvas.selectAll("rect")
            .data(data)
            .enter()
                .append("rect")
                .attr("width", function(d){ return d.age *10;})
                .attr("height", 50)
                .attr("y", function(d ,i){ return i* 50; })
                .attr("fill", "blue");
    });

    </script>
Share Improve this question asked Jan 9, 2014 at 0:19 mross1080mross1080 1541 silver badge7 bronze badges 2
  • Are this html file and mydata.json in the same directory? – bnuhero Commented Jan 9, 2014 at 0:28
  • Yeah both locally and on the server, im pretty sure the problem is that the JSON file that I wrote is being saved as a text/html file. I saved it as mydata.json but because I wrote it in sublime 2 i think there was a problem – mross1080 Commented Jan 9, 2014 at 2:09
Add a ment  | 

2 Answers 2

Reset to default 4

Take a look at this and this gotchas. Let us know if you succeeded accessing json after that.

You guys need not change any Formats. Just need to change some settings in Server.Here I am using IIS server so I have tested my files and got same 404 error for JSON Files and I made the following changes and it worked like a Charm. You just follow this If you are using an IIS Server...

Step 1: Open IIS Server and go to MIME Types

Step2: Click Add from right side and add JSON extension and restart the server

发布评论

评论列表(0)

  1. 暂无评论