jqGrid postData empty when use with ajaxGridOptions

社会主义新天地 提交于 2019-12-23 04:23:12

问题


Below is my jqGrid initialisation:

            jQuery("#dataGrid").jqGrid({
            jsonReader : {
              root:"rows",
              page: "page",
              total: "total",
              records: "records",
              cell: "",
              id: "0" 
           },
           postData: {
           page: function() { return page; }
           },
            url: 'WebService.asmx/GetData',
            datatype: "json",
            mtype: "POST",
            ajaxGridOptions: {
               contentType: "application/json; charset=utf-8"
            },
            serializeGridData: function (data) {
                return JSON.stringify(data);
            },
            colNames: [<%= colName %>],
            colModel: [<%= colModal %>],
            rowNum: 10,
            rowList: [10, 20, 30],
           pager: '#dataGrid_Pager',
            sortname: 'name',
            viewrecords: true,
            sortorder: "name",
            caption: "JSON Example"
        });

There is no problem displaying the data on the grid. However, in my web service the postData is empty. i.e. context.request.form(0) is empty.

When I removed this from the code:

ajaxGridOptions: {
               contentType: "application/json; charset=utf-8"
            },

postData contains this when I add a watch to context.request.form(0):

{"page":1,"_search":false,"nd":1394031676148,"rows":10,"sidx":"name","sord":"name"}

But now, the grid is empty with no grid data.

Seems like postData is conflicting with the ajaxGridOptions?

Anyone can advise? I need both of them to work together.

Thanks!


回答1:


Solved my problem. Sorry for the newbie-ness.

Once content is set to json, there will be no post data. The JSON reply is actually in the context.request.inputStream.

You can get back the data by converting it to an object through the following:

Dim jss As New JavaScriptSerializer
    Context.Request.InputStream.Position = 0
    Dim sr As New StreamReader(Context.Request.InputStream)
    Dim jsonString As String = sr.ReadToEnd()
    Dim jsObj As Object = jss.DeserializeObject(jsonString)

You will be able to get the data posted by doing jsObj("page"), jsObj("_search") etc...

Hope this helps someone.

Thanks.



来源:https://stackoverflow.com/questions/22201492/jqgrid-postdata-empty-when-use-with-ajaxgridoptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!