为什么我的JSON文件没有发现? [英] Why is my json file not found?
问题描述
我有我的asp.net项目中的内容文件夹中的JSON文件:
<&PROJECTNAME GT;
\\内容
NBCCJr.json
...和code访问它:
$。的getJSON(〜/内容/ NBCCJr.json'功能(数据){
$。每个(数据,功能(I,数据点){
//布拉
});
});
)
...但没有任何反应时,code被调用;浏览器控制台说,无法加载资源:服务器的状态为回应404(未找到)
为什么没有发现?是不是波浪失衡文件名的文件的正确路径?
更新
我也与whacks向后试了一下
$。的getJSON('〜\\内容\\ NBCCJr.json'功能(数据){
...并得到了同样的结果(无法加载资源:服务器的状态为回应404(未找到)的)
更新2
然后我尝试了SAN中的一个prepended正是如此重击:
$。的getJSON(内容/ NBCCJr.json'功能(数据){
...我得在控制台这个暧昧的短信:
* GET HTTP://本地主机:9702 /内容/ NBCCJr.json 404(未找到)的jquery.js:8724
XHR加载完成:HTTP://本地主机:9702 /内容/ NBCCJr.json。*
所以没有被发现,但无论如何装?
更新3
当我试图通过更改导航到浏览器中的文件:
的http://本地主机:9702 / Default.cshtml
...为:
的http://本地主机:9702 /内容/ NBCCJr.json
我从文顿·瑟夫,蒂姆·伯纳斯 - 李一个信息WSOD消息,和/或戈尔说:
的 HTTP错误404.3 - 未找到
您请求的页面不能因为扩展配置的送达。如果页面是一个脚本,添加处理程序。如果该文件应该被下载,添加MIME映射。的
更新4
由于JAM,它现在的工作。
我不得不把它添加到Web.config中:
< system.webServer>
< staticContent>
< mimeMap fileExtension = mime类型=应用/ JSON/&GTJSON。
< / staticContent>
< /system.webServer>
您是否尝试过删除〜
?
如:
$。的getJSON('/内容/ dumboJr.json'功能(数据){
$。每个(数据,功能(I,数据点){
//布拉
});
});
)
要允许IIS服务JSON文件,你可以添加以下到你的web.config:
< staticContent>
< mimeMap fileExtension = mime类型=应用/ JSON/&GTJSON。
< / staticContent>
I have a json file in a Content folder within my asp.net project:
<projectName>
\Content
NBCCJr.json
...and the code to access it:
$.getJSON('~/Content/NBCCJr.json', function (data) {
$.each(data, function(i, dataPoint) {
// Bla
});
});
)
...but nothing happens when the code is called; the browser console says, "Failed to load resource: the server responded with a status of 404 (Not Found)"
Why is it not found? Isn't "tilde whack filename" the correct route to the file?
UPDATE
I also tried it with the "whacks" backwards:
$.getJSON('~\Content\NBCCJr.json', function (data) {
...and got the same result ("Failed to load resource: the server responded with a status of 404 (Not Found)")
UPDATE 2
Then I tried it sans a prepended whack thusly:
$.getJSON('Content/NBCCJr.json', function (data) {
...and I get this ambiguous message in the console:
*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?
UPDATE 3
When I attempted to navigate to the file in the browser by changing:
http://localhost:9702/Default.cshtml
...to:
http://localhost:9702/Content/NBCCJr.json
I got an informative WSOD message from Vint Cerf, Tim Berners-Lee, and/or Al Gore saying:
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.
UPDATE 4
Thanks to JAM, it is now working.
I had to add this to Web.Config:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
Have you tried removing the ~
?
As in:
$.getJSON('/Content/dumboJr.json', function (data) {
$.each(data, function(i, dataPoint) {
// Bla
});
});
)
To allow the IIS to serve JSON files, try adding this to your web.config:
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
这篇关于为什么我的JSON文件没有发现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!