jQWidgets Forums

jQuery UI Widgets Forums Grid Sending POST data does not send JSON.

This topic contains 1 reply, has 1 voice, and was last updated by  realtek 11 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Sending POST data does not send JSON. #31834

    realtek
    Participant

    Hi,

    I have tried everything to get my Grid to send data in a JSON format when using POST but it ALWAYS tried to use URLEncoded string.

    Basically, I had this all working in PHP but I moved to a WCF Web Service in .NET. But unfortunately I need to POST an object which can only be done using POST and not GET.

    I have tried setting the Content-Type in the Request, also set ‘processData’ to false and nothing seems to work. Its also as if there is something else which is actually doing the ajax call rather even trying to use the parameters I set in the source – perhaps I am doing something wrong! I also get a lot of other bits of data such as ‘filterscount’ and ‘recordendindex’ in the request.

    I have also tried JSON.Stringify which I was using rather than my variable “datatest” below.

    His is my code for the ‘source’ – I also found out to send JSON as the data you need to put the single quotes around the { } for JSON otherwise its sent as a javascript object, not JSON.

    var datatest = ‘{ test1 : “1”, test2: “2”, test3 : “18” }’;
    var url = “webservices/mainGrid/Nick.svc/GetRecords”
    var source = {
    type: “POST”,
    dataType: ‘json’,
    url: url,
    id: “SEQUENCE”,
    root: ‘rowsinfo’,
    contentType: “application/json; charset=utf-8”,
    processData: false,
    async: false,
    cache: false,
    columns:[],
    datafields:[],
    beforeprocessing: function (data) {
    var columnsdata = new Array();
    var datafieldsdata = new Array();
    for (k in data.columnsinfo){
    var col={};
    col.text = data.columnsinfo[k][“DISPLAYNAME”];
    col.datafield = data.columnsinfo[k][“DISPLAYNAME”];
    var datafields={};
    datafields.name = data.columnsinfo[k][“DISPLAYNAME”];
    columnsdata .push(col);
    datafieldsdata .push(datafields);
    source.columns = columnsdata;
    source.datafields = datafieldsdata;
    }
    $(“#jqxgrid”).jqxGrid({columns : source.columns});
    },
    data: datatest
    };

    Any help would be great, I have spent days on this thinking it was my WCF!

    Perhaps it needs all setting somewhere else and not in the source?

    Thanks

    Sending POST data does not send JSON. #31835

    realtek
    Participant

    ok, after days of looking at this I have found the solution right in the documentation!

    I just needed to use ‘formatData’ function instead of ‘data’

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.