I have a json file in a Content folder within my asp.net project:
<projectName>
\Content
NBCCJr.json
.以及访问它的代码:
$.getJSON('~/Content/NBCCJr.json', function (data) {
$.each(data, function(i, dataPoint) {
// Bla
});
});
)
...但是当代码被调用时,什么也不会发生;浏览器控制台显示"加载资源失败:服务器响应状态为404(未找到)"
为什么找不到?"tilde-whack-filename"不是文件的正确路径吗?
使现代化
我也试过用"重击"倒过来:
$.getJSON('~\Content\NBCCJr.json', function (data) {
.并得到相同的结果("Failed to load resource: the server responded with a status of 404 (Not Found)")
使现代化 2
然后我试了一下,没有预先准备好的重击:
$.getJSON('Content/NBCCJr.json', function (data) {
.我在控制台上收到了这条模棱两可的信息:
*GET http://localhost:9702/Content/NBCCJr.json 404 (Not Found) jquery.js:8724
XHR finished loading: "http://localhost:9702/Content/NBCCJr.json".*
So it was not found and yet loaded anyway?
使现代化 3
When I attempted to navigate to the file in the browser by changing:
http://localhost:9702/Default.cshtml
...致:
http://localhost:9702/Content/NBCCJr.json
我从温特·瑟夫、蒂姆·伯纳斯·李和/或阿尔·戈尔那里得到了一条信息丰富的WSOD信息,说:
HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
使现代化 4
Thanks to JAM, it is now working.
我不得不把这个添加到网络上.配置:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>