我需要从ASP.NET MVC的“App_Data”文件夹加载Geojson文件,并在d3.json中使用它。
d3.json("@Server.MapPath("~/App_Data/data/afile.geojson")", function (error, geodata) {
if (error) return console.log(error);
features.selectAll("path")
.data(geodata.features)
...
}
我看到了错误:
error { target: XMLHttpRequest, isTrusted: true, lengthComputable: false, loaded: 0, total: 0, currentTarget: XMLHttpRequest, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, … }
在“查看页面源”中:
d3.json("C:\Users\user\Documents\Visual Studio 2013\Projects\ASP.NET\app\app\App_Data\data\afile.geojson", function (error, geodata) {
if (error) return console.log(error);
...
}
怎么解决这个?
下面的代码应该添加到Web.config(而不是web.config)。
<system.webServer>
<staticContent>
<mimeMap fileExtension=".geojson" mimeType="application/geojson" />
</staticContent>
</system.webServer>
在名为“Data”的文件夹中使用文件。
d3.json("/Data/geo/afile.geojson", function (error, geodata) {
... }
我在使用“App_Data”文件夹时看到错误。
d3.json("/App_Data/geo/afile.geojson", function (error, geodata) {
... }