0

我这里有一个问题,我使用 postdata 将参数从 ASPX 文件发送到 web 服务,而没有使用ajaxGridOptions: { contentType: 'application/json; charset=utf-8'}.

问题是,网格不显示来自 web 服务的内容,一旦我们使用它ajaxGridOptions: { contentType: 'application/json; charset=utf-8'},网格就不会将任何参数传递给 web 服务。这是我们的jqgrid代码,请帮忙

$(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');
});
4

1 回答 1

2

您必须将节点:ajaxGridOptions放入您的 jqGrid 选项对象中。

于 2013-04-25T09:20:32.190 回答