문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top