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
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
当前回答
内春春您有一个定义型号 :MediaType.APPLICATION_JSON_VALUE
等于申请/日文.
其他回答
“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())
}
}
Content-Type: application/json
-杰森Content-Type: application/javascript
- 杰森-普Content-Type: application/x-javascript
- JavaScriptContent-Type: text/javascript
- JavaScript 但是,但用于 HTML 属性的旧的因特网探索者版本。Content-Type: text/x-javascript
- JavaScript媒体类型,但是,但过时Content-Type: text/x-json
- 曾经杰森申请/日文正式注册。PHP 开发商使用此功能 :
<?php
header("Content-type: application/json");
// Do something here...
?>
当然,对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);
}
};