How to jsonify “Add” post/parameters for jqGrid

前端 未结 1 883
暖寄归人
暖寄归人 2021-01-17 01:00

This one\'s killing me. I\'ve read through a lot of Oleg\'s comments, and through the documentation, but I think I\'m overlooking something really

1条回答
  •  孤城傲影
    2021-01-17 01:24

    In my opinion your main problem is in JS - Globals. You use jQuery.extend function in a wrong way. You should replace one call

    jQuery.extend(
        jQuery.jgrid.defaults, {
            // ...
        },
        jQuery.jgrid.edit, {
            // ...
        }
    );
    

    to two separate calls:

    jQuery.extend(
        jQuery.jgrid.defaults, {
            // ...
        }
    );
    jQuery.extend(
        jQuery.jgrid.edit, {
            // ...
        }
    );
    

    After that the edit request to the server will be {"FileType":3,"ExportDate"="12/29/2010","oper":"add","id":"_empty"} instead of FileType=3&ExportDate=12%2F29%2F2010&oper=add&id=_empty.

    Next, I am not sure that you can use ExportDate as a Date (DateTime ???) type. Probably you should start with String type and then convert the input data to the datatype which you need.

    Next remark. Be sure that ModifyFileLog return JSON data. For example you can use instead of . If you use .NET 4.0 you can achieve the same in many other ways.

    One more thing. The ModifyFileLog should be Function instead of Sub and return the Id of new added object. In case of edit or del operations the return value will be ignored.

    Because ModifyFileLog Function will be returned JSON data you have to decode/parse it. You can do this almost in the same way which I described here. In case of ASMX web service you can do about following:

    jQuery.extend(
        jQuery.jgrid.edit, {
            ajaxEditOptions: { contentType: "application/json" },
            recreateForm: true,
            serializeEditData: function(postData) {
                return JSON.stringify(postData);
            },
            afterSubmit: function (response, postdata) {
                var res = jQuery.parseJSON(response.responseText);
                return [true, "", res.d];
            }
        }
    );
    

    0 讨论(0)
提交回复
热议问题