JSON File Extension

后端 未结 3 1335
轮回少年
轮回少年 2021-02-15 17:17

I\'ve been saving all my json files with .txt extension and they worked with jquery ajax calls.

When I change the extension to .json and in my jquery ajax call --

3条回答
  •  礼貌的吻别
    2021-02-15 17:29

    IIS comes bundled with a bunch of MIME type handlers. This means when you enter a URL that ends with, for example, .png, IIS knows that this is an image, and dispatches the appropriate response to tell the client (browser) that it's an image (so it can be rendered as such).

    .json doesn't have a MIME type handler by default. You need to set one up:

    • Load IIS Manager
    • Browse the tree nodes up to your web app or website
    • Double click on the MIME Types feature (lower pane)
    • Click Add (RHS under "Add", or right-click and pick Add)
    • Put .txt under the extension field and application/json as the MIME type

    You're done! Try requesting the JSON file in the browser; if it renders correctly (as text), awesome. If not, you may have to tell IIS to render it as text/plain instead.

提交回复
热议问题