[英]Recieving the edit/add data from jqGrid in x-www-form-urlencoded, i need application/json
I am trying to link my jqGrid to my Java Rest service. 我试图将我的jqGrid链接到我的Java Rest服务。 When i send the edit/add data from jqGrid to my rest in order to process it for DB CRUD operations, i recieve it like this :
当我将编辑/添加数据从jqGrid发送到我的其余部分以便处理它以进行DB CRUD操作时,我收到它像这样:
"nume=Alin&prenume=Dan&sefDepartament=Yes&position=position+2&joinYear=2015-08-11&oper=edit&id=2"
I need to recieve it in a JSON format. 我需要以JSON格式接收它。 How can i achieve that?
我怎样才能实现这一目标?
This is my Java piece of code : 这是我的Java代码:
@Path("/update")
public class UpdateDatabase {
@POST
public String updateDatabase(String data){
System.out.println(data);
}
This is my jqGrid settings i have regarding the server connection: 这是我关于服务器连接的jqGrid设置:
grid.jqGrid({
pager: '#pager',
mtype: "POST",
url: "/RestWithDatabaseConnection/rest/fetchData",
editurl:'/RestWithDatabaseConnection/rest/update',
datatype: "json",
Please let me know if i should add some other information. 如果我应该添加一些其他信息,请告诉我。
To send the results of editing encoded in JSON format one should 要发送以JSON格式编码的编辑结果,应该
Content-Type: application/json
in the HTTP header Content-Type: application/json
JSON.stringify
to encode the posted data JSON.stringify
对发布的数据进行编码 If you use free jqGrid then you can use the following inlineEditing
option, which are the options of jqGrid (in the same level where editurl
) 如果您使用免费的jqGrid那么你可以使用下面的
inlineEditing
选项,这是jqGrid的选项(在相同的水平, editurl
)
inlineEditing: {
ajaxSaveOptions: { contentType: "application/json" },
serializeSaveData: function (postData) {
return JSON.stringify(postData);
}
}
In case of usage old jqGrid versions you can use jqGrid options ajaxRowOptions
and serializeRowData
in almost the same way: 如果使用旧的jqGrid版本,您可以以几乎相同的方式使用jqGrid选项
ajaxRowOptions
和serializeRowData
:
ajaxRowOptions: { contentType: "application/json" },
serializeRowData: function (postData) {
return JSON.stringify(postData);
}
Free jqGrid supports jqGridInlineSerializeSaveData
event as alternative to serializeSaveData
or serializeRowData
callback. free jqGrid支持
jqGridInlineSerializeSaveData
事件,作为serializeSaveData
或serializeRowData
回调的替代。 It's helpful in more advances scenarios. 它在更多进步方案中很有用。 The options
ajaxRowOptions
and serializeRowData
are supported by free jqGrid too because of the compatibility reasons. 由于兼容性原因,自由jqGrid也支持选项
ajaxRowOptions
和serializeRowData
。
I would recommend you to consider to use free jqGrid 4.12.0 or the latest source from GitHub. 我建议你考虑使用免费的jqGrid 4.12.0或GitHub的最新资源。 The list on main new features and the bug fixes is described in the readme as usually.
主要新功能和错误修复的列表通常在自述文件中描述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.