0

i have a problem here, i used postdata to send parameters from ASPX file to the webservice, without using ajaxGridOptions: { contentType: 'application/json; charset=utf-8'}.

The problem is, the grid does not display the contents from the webservice and once we use this ajaxGridOptions: { contentType: 'application/json; charset=utf-8'} the grid does not pass any of the parameters to the webservice. Here is our jqgrid code, please help

$(document).ready(function () {
  var myGrid = $("#list");
  myGrid.jqGrid({
    url: '/priParentsContribution.asmx/getListOfTeachers',
    datatype: 'json',
    mtype: 'POST',
    //ajaxGridOptions: { contentType: 'application/json; charset=utf-8'}
    jsonReader: {
      repeatitems: true,
      root: "d.rows",
      page: "d.page",
      total: "d.total",
      records: "d.records"
    },
    colModel: [{
        name: 'feePurpose',
        index: 'feePurpose',
        width: 100,
        editable: true,
        edittype: 'select',
        editoptions: {
          value: "0:--Select--;Books:Books;Uniform:Uniform"
        }
      },
      {
        name: 'standard1',
        index: 'standard1',
        width: 100,
        editable: true
      }, {
        name: 'standard2',
        index: 'standard2',
        width: 100,
        editable: true
      }, {
        name: 'standard3',
        index: 'standard3',
        width: 100,
        editable: true
      }, {
        name: 'standard4',
        index: 'standard4',
        width: 100,
        editable: true
      }, {
        name: 'standard5',
        index: 'standard5',
        width: 100,
        editable: true
      }, {
        name: 'standard6',
        index: 'standard6',
        width: 100,
        editable: true
      }, {
        name: 'standard7',
        index: 'standard7',
        width: 100,
        editable: true
      }
    ],
    forceFit: true,
    rowNum: 10,
    rowList: [10, 20, 30],
    pager: "#pager",
    viewrecords: true,
    gridview: true,
    width: 1200,
    height: 300,
    loadonce: true, //THIS IS IMPORTANT !!!
    postData: {
      advertiserID: function () {
        return $("#advertiserId").val();
      },
    },
    ajaxGridOptions: {
      contentType: "application/json",
      success: function (data, textStatus) {
        if (textStatus == "success") {
          var thegrid = myGrid[0];
          thegrid.addJSONData(data.d);
          thegrid.grid.hDiv.loading = false;
          switch (thegrid.p.loadui) {
          case "disable":
            break;
          case "enable":
            $("#load_" + thegrid.p.id).hide();
            break;
          case "block":
            $("#lui_" + thegrid.p.id).hide();
            $("#load_" + thegrid.p.id).hide();
            break;
          }
        }
      }
    },
    ajaxGridOptions: {
      contentType: 'application/json; charset=utf-8',
      dataType: "json",
      type: "POST",
      cach: false
    },
    //rowNum: 100,
    serializeGridData: function (postData) {
      var propertyName, propertyValue, dataToSend = {};
      for (propertyName in postData) {
        if (postData.hasOwnProperty(propertyName)) {
          propertyValue = postData[propertyName];
          if ($.isFunction(propertyValue)) {
            dataToSend[propertyName] = propertyValue();
          } else {
            dataToSend[propertyName] = propertyValue
          }
        }
      }
      return JSON.stringify(dataToSend);
    }    
  });
  $("#reload").click(function () {
    myGrid.trigger("reloadGrid");
  });
  myGrid.jqGrid('navGrid', '#pager', {
    edit: false,
    add: false,
    del: true,
    search: false,
    search: false,
    view: false
  });
  myGrid.jqGrid('inlineNav', '#pager');
});
MikO
  • 18,243
  • 12
  • 77
  • 109
user2298771
  • 1
  • 1
  • 1
  • 1
    You included in the code `ajaxGridOptions` option **twice**. You should don't overwrite default `success` callback of jQuery.ajax with youth in `ajaxGridOptions`. You should include `loadError` callback (see [the answer](http://stackoverflow.com/a/6969114/315935)) to know *which error* you have. You can use [Fiddler](http://fiddler2.com/get-fiddler) of Developer Tools (press F12 in IE to start) to trace HTTP traffic. You will see whether the request will be send to the server, whether the server respond and so on. – Oleg Apr 19 '13 at 11:48

1 Answers1

2

You have to nodes : ajaxGridOptions into your jqGrid options object.

G. Ghez
  • 3,429
  • 2
  • 21
  • 18