简体   繁体   English

在x-www-form-urlencoded中从jqGrid接收编辑/添加数据,我需要application / json

[英]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格式编码的编辑结果,应该

  1. set Content-Type: application/json in the HTTP header 在HTTP标头中设置Content-Type: application/json
  2. use 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选项ajaxRowOptionsserializeRowData

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事件,作为serializeSaveDataserializeRowData回调的替代。 It's helpful in more advances scenarios. 它在更多进步方案中很有用。 The options ajaxRowOptions and serializeRowData are supported by free jqGrid too because of the compatibility reasons. 由于兼容性原因,自由jqGrid也支持选项ajaxRowOptionsserializeRowData

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.

相关问题 将JSON用作application / x-www-form-urlencoded - Consuming JSON as application/x-www-form-urlencoded Jersey Client 可以自动将 POJO 实体编码为 application/x-www-form-urlencoded,还是我需要编写自定义 MessageBodyWriter? - Can Jersey Client automatically encode POJO entities into application/x-www-form-urlencoded, or do I need to write custom MessageBodyWriter? 未找到Form&application / x-www-form-urlencoded的Body Writer - Body Writer not found for Form & application/x-www-form-urlencoded 如何编写控制器类以允许内容类型:application / json和application / x-www-form-urlencoded - How to write controller class to allow content-type: application/json and application/x-www-form-urlencoded 泽西同时使用application / json和application / x-www-form-urlencoded - Jersey consuming both application/json and application/x-www-form-urlencoded 泽西岛:使用application / json和application / x-www-form-urlencoded并进行测试 - Jersey: Consuming application/json and application/x-www-form-urlencoded and testing it ModelAttribute未映射application / x-www-form-urlencoded - ModelAttribute not mapping application/x-www-form-urlencoded 具有注入的MultivaluedMap的注入提供程序(application / x-www-form-urlencoded) - Injection provider with injected MultivaluedMap (application/x-www-form-urlencoded) POST 调用接受 x-www-form-urlencoded 但拒绝 JSON - POST call accepts x-www-form-urlencoded but refuses JSON 使用 ClientBuilder 发送 JSON 正文,但使用 ContentType=application/x-www-form-urlencoded - Send JSON body but with ContentType=application/x-www-form-urlencoded with ClientBuilder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM