与ajaxGridOptions一起使用时,jqGrid postData为空 [英] jqGrid postData empty when use with ajaxGridOptions

查看:493
本文介绍了与ajaxGridOptions一起使用时,jqGrid postData为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的jqGrid初始化:

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"
        });

在网格上显示数据没有问题.但是,在我的Web服务中,postData为空.即context.request.form(0)为空.

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"
            },

当我将手表添加到context.request.form(0)时,

postData包含此内容:

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.

好像postData与ajaxGridOptions冲突?

Seems like postData is conflicting with the ajaxGridOptions?

任何人都可以建议吗?我需要他们两个一起工作.

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

谢谢!

推荐答案

解决了我的问题.抱歉,是新手.

Solved my problem. Sorry for the newbie-ness.

一旦将内容设置为json,就不会发布任何数据. JSON回复实际上在context.request.inputStream中.

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)

您将可以通过执行jsObj("page"),jsObj("_ search")等来获取发布的数据.

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

希望这对某人有帮助.

Hope this helps someone.

谢谢.

这篇关于与ajaxGridOptions一起使用时,jqGrid postData为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆