developer tip

내 json 파일을 찾을 수없는 이유는 무엇입니까?

copycodes 2020. 9. 19. 11:29
반응형

내 json 파일을 찾을 수없는 이유는 무엇입니까?


내 asp.net 프로젝트의 Content 폴더에 json 파일이 있습니다.

<projectName>
    \Content
        NBCCJr.json

... 그리고 그것에 액세스하는 코드 :

$.getJSON('~/Content/NBCCJr.json', function (data) {
    $.each(data, function(i, dataPoint) {
        // Bla
      });
  });
)

...하지만 코드가 호출 될 때 아무 일도 일어나지 않습니다. 브라우저 콘솔에 "리소스로드 실패 : 서버가 404 (찾을 수 없음) 상태로 응답했습니다."라고 표시됩니다.

왜 찾을 수 없습니까? "물결 파일 이름"이 파일에 대한 올바른 경로가 아닙니까?

최신 정보

나는 또한 "whacks"를 거꾸로 시도했다.

$.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".*

그래서 그것은 발견되지 않았고 어쨌든로드 되었습니까?

업데이트 3

다음을 변경하여 브라우저에서 파일로 이동하려고 할 때 :

http://localhost:9702/Default.cshtml

...에:

http://localhost:9702/Content/NBCCJr.json

Vint Cerf, Tim Berners-Lee 및 / 또는 Al Gore로부터 유익한 WSOD 메시지를 받았습니다.

HTTP 오류 404.3-찾을 수 없음 확장 구성으로 인해 요청한 페이지를 제공 할 수 없습니다. 페이지가 스크립트 인 경우 핸들러를 추가하십시오. 파일을 다운로드해야하는 경우 MIME 맵을 추가하십시오.

업데이트 4

JAM 덕분에 이제 작동합니다.

이것을 Web.Config에 추가해야했습니다.

  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>

제거하려고 했습니까 ~?

에서와 같이 :

$.getJSON('/Content/dumboJr.json', function (data) {
    $.each(data, function(i, dataPoint) {
        // Bla
      });
  });
)

IIS가 JSON 파일을 제공하도록 허용하려면 다음을 web.config에 추가해보십시오.

<staticContent>
    <mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>

해결책은 MIME 유형에 json 파일 확장자 유형을 추가해야한다는 것입니다.

방법 1

IIS로 이동하여 응용 프로그램을 선택하고 MIME 유형 찾기

enter image description here

오른쪽 패널에서 추가를 클릭하십시오.

파일 이름 확장자 = .json

MIME 유형 = application / json

enter image description here

After adding .json file type in MIME Types, Restart IIS and try to access json file


Method 2

Go to web.config of that application and add this lines in it

 <system.webServer>
   <staticContent>
     <mimeMap fileExtension=".json" mimeType="application/json" />
   </staticContent>
 </system.webServer>

Try putting the *.json file in the webRoot, not in a sub folder. And then reference it like:

$.getJSON('NBCCJr.json', function (data) {

This of course requires the previous inclusion and instantiation of the jQuery system object from: jquery.min.js or the JSON structure from: json2-1.0.min.js


I Changed .json to .txt and request is working fine. I am not sure about the consequence .txt can cause.

참고URL : https://stackoverflow.com/questions/17626776/why-is-my-json-file-not-found

반응형