代码之家  ›  专栏  ›  技术社区  ›  bugfixr

jqGrid使用json调用WebService(asmx)

  •  1
  • bugfixr  · 技术社区  · 15 年前

    $("#jqCategoryGrid").jqGrid({
        datatype: "json",
        mtype: 'POST',        
        url: "Webservices/TroubleTicketCategory.asmx/getCategoryData",
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        // **UPDATE - This is the fix, as per Oleg's response**
        serializeGridData: function (postData) {
            if (postData.searchField === undefined) postData.searchField = null;
            if (postData.searchString === undefined) postData.searchString = null;
            if (postData.searchOper === undefined) postData.searchOper = null;
            //if (postData.filters === undefined) postData.filters = null;
            return JSON.stringify(postData);
        },
    });
    

    问题是jqGrid仍在尝试使用非json格式传递参数,因此我得到了一个错误“invalidjson Primitive”

    有没有方法指示jqGrid使用Json序列化数据?

    谢谢

    我编辑了我的问题中提供的源代码,以包括我使用的修复程序,它来自下面Oleg的回答。

    1 回复  |  直到 15 年前
        1
  •  2
  •   Oleg    13 年前

    您应该包括发布数据的JSON序列化,例如关于json2.js的序列化,可以从 http://www.json.org/js.html

    serializeRowData: function (data) { return JSON.stringify(data); }
    
    推荐文章