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
我用哪一种,在哪里?我假设安全和浏览器支持问题是一个因素。
当前回答
缩略内容类型标题应该设置为 '申请/日文收听请求的服务器应包含 "接受=申请/json"在春季MVC中,你可以这样做:
@RequestMapping(value="location", method = RequestMethod.POST, headers = "Accept=application/json")
回复中的添加页眉 :
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
其他回答
正确的答案是:
Content-Type: application/json
当然,对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);
}
};
PHP 开发商使用此功能 :
<?php
header("Content-type: application/json");
// Do something here...
?>
“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())
}
}