JSON文件扩展名 [英] JSON File Extension
问题描述
我一直保存着所有带有.txt扩展名的json文件,它们与jquery ajax调用一起使用.
I've been saving all my json files with .txt extension and they worked with jquery ajax calls.
当我将扩展名更改为.json并在我的jquery ajax调用中- jQuery.ajax()-我指定
When I change the extension to .json and in my jquery ajax call -- jQuery.ajax() -- I specify
- dataType:"json",
- contentType:"application/json; charset = utf-8",
文件不再起作用.为什么这样?
the files no longer work. Why so?
不是所有的json文件都具有扩展名.json吗?我正在使用IIS服务器.
Shouldn't all json files have an extension .json? I'm using IIS server.
JSON
{ "rows": [
{"row":[
{"cells": [
{"data": "Edit"},
{"data": "030194"}
]}
]},
{"row":[
{"cells": [
{"data": "Add"},
{"data": "030194"}
]}
]}
]}
jQuery
jQuery.ajax ({
type: "GET",
url: "localhost/ABC.json",
dataType: "json",
contentType: "application/json;
charset=utf-8",
cache: "false",
success: function(response){}
});
有人可以告诉我为什么扩展名.json不起作用吗?如果我将其更改为.txt
推荐答案
正确的扩展名为.json
,MIME类型为application/json
(参考:
The correct extension is .json
, and the mime type is application/json
(reference: this Wikipedia page). Generally speaking, however, it should work with any extension so long as your data structure is valid and your web server is doing what it's supposed to.
这篇关于JSON文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!