bugfixr
bugfixr

Reputation: 8077

jqGrid calling WebService (asmx) using json

I've got a jqGrid setup to post to a URL using the content type of application/json:

$("#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);
    },
});

The problem is that the jqGrid is still trying to pass parameters using a non-json format so I'm getting an error "Invalid JSON Primitive"

Is there a way to instruct the jqGrid to serialize the data using Json?

Thanks

UPDATE

I edited the provided source code in my question to include the fix I used, which came from Oleg's response below.

Upvotes: 1

Views: 4116

Answers (1)

Oleg
Oleg

Reputation: 221997

You should include JSON serialization of the posted data for example with respect of json2.js which can be downloaded from http://www.json.org/js.html:

serializeRowData: function (data) { return JSON.stringify(data); }

Upvotes: 2

Related Questions