application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
当前回答
根据在 URL 中传递的查询参数, 回复是动态生成的数据 。
示例:
{ "Name": "Foo", "Id": 1234, "Rank": 7 }
内容类型 : application/json
JSON用垫子。回应是 JSON数据, 并有一个功能电话围绕它。
示例:
functionCall({"Name": "Foo", "Id": 1234, "Rank": 7});
内容类型 : application/javascript
其他回答
“application/json
”是正确的JSON内容类型。
def ajaxFindSystems = {
def result = Systems.list()
render(contentType:'application/json') {
results {
result.each{sys->
system(id:sys.id, name:sys.name)
}
}
resultset (rows:result.size())
}
}
当然,对JSON来说正确的MIME媒体类型是application/json
,但有必要了解在您的应用程序中预期会收到何种类型的数据。
例如,我使用Ext GWT 离 GWT服务器响应必须以文本/ html但包含JSON的数据。
客户端, Ext GWT 窗体收听器
uploadForm.getForm().addListener(new FormListenerAdapter()
{
@Override
public void onActionFailed(Form form, int httpStatus, String responseText)
{
MessageBox.alert("Error");
}
@Override
public void onActionComplete(Form form, int httpStatus, String responseText)
{
MessageBox.alert("Success");
}
});
使用申请/日文响应类型,浏览器建议我保存文件。
服务器侧端源代码片断使用春春MVC
return new AbstractUrlBasedView()
{
@SuppressWarnings("unchecked")
@Override
protected void renderMergedOutputModel(Map model, HttpServletRequest request,
HttpServletResponse response) throws Exception
{
response.setContentType("text/html");
response.getWriter().write(json);
}
};
如果您使用 Ubuntu 或 Debian 或 Debian , 通过 Apache 服务于 .json 文件, 您可能需要以正确内容类型服务文件。 我这样做主要是因为我想使用 Firefox 扩展名Json View 吉森(Jsson View )
Apache 模块调制(_mime)将会帮助您轻松完成此操作 。 但是, 您需要用 Ubuntu 来编辑文件/eec/mime.类型添加一行
application/json json
然后重新启动 Apache :
sudo service apache2 restart
为补充先前的答复,JSON 链接数据的MIME类型(JSON-LD)以 W3C 计算是:
application/ld+json
类型名称 :应用
子类型名称 :Ld+json 键盘
此外,来自同一来源的:
文件扩展名:
.jsonld
PHP 开发商使用此功能 :
<?php
header("Content-type: application/json");
// Do something here...
?>