2012-05-16 71 views
1

爲什麼PostData值永遠不會發送到服務器?如果我用戶fixwed值POSTDATA:{測試:「3」}它的工作原理,但使用功能沒有被傳遞到服務器時..... 螢火蟲不露測試變量postData未發送到服務器jqgrid

$("#tblgrid").jqGrid({ 
      datatype: 'json', 
      ajaxGridOptions: { contentType: "application/json" }, 
      ajaxRowOptions: { contentType: "application/json", type: "POST" }, //row inline editing 
      serializeGridData: function(postData) { return JSON.stringify(postData); }, 
      jsonReader: { 
       repeatitems: false, 
       id: "0", 
       cell: "", 
       root: function(obj) { return obj.d.rows; }, 
       page: function(obj) { return obj.d.page; }, 
       total: function(obj) { return obj.d.total; }, 
       records: function(obj) { return obj.d.records; } 
      }, 
      url: 'orthofixServices.asmx/GetProductList', 
      postData: { test: function() { return $("#tid").val(); } }, 
      datatype: 'json', 
      colNames: ['id', 'Product Description', 'Commission Rate'], 
      colModel: [ 
      { name: 'id', width: 50 }, 
      { name: 'description', index: 'desc', width: 380, editable: true }, 
      { name: 'commissionrate', index: 'com', width: 120, editable: true, unformat: percentUnFormatter, formatter: percentFormatter, editrules: { number: true} } 
      ], 
      serializeRowData: function(data) { 

       var params = new Object(); 
       params.id = 0; 
       params.prdid = 4; 
       params.description = data.description; 
       params.commissionrate = data.commissionrate; 
       var result = JSON.stringify({ 'passformvalue': params, 'oper': data.oper, 'id': data.id }); 
       return result; 
      }, 
      mtype: "POST", 

      rowNum: 4, 
      width: 500, 
      height: 80, 
      pager: '#pager', 
      editurl: "orthofixServices.asmx/ModifyProductList" 
     }); 
     $("#tblgrid").jqGrid('navGrid', '#pager', { add: false, edit: false, del: true }, { 
     //edit options 

    }, { 
    //add options  

}, { 
//delete options 

的任何蹤跡});

回答

0

postData字段表示數據要被髮送到服務器:

此陣列被直接傳遞給URL。這是關聯數組,可以這樣使用:{name1:value1...}

你的代碼的問題在於你試圖將一個函數(代碼)傳遞給服務器。相反,你需要直接傳遞數據:

postData: { test: $("#tid").val() } 
+1

我試圖做的是在這裏解釋說:http://stackoverflow.com/questions/2826478/jqgrid-not-updating-data-on-reload。所以postData似乎接受一個函數,它會在每次重新加載網格時動態更新 –

0

你需要實際執行已設置你的POSTDATA的職能。

添加到這一點您serializeRowData:

    for (propertyName in data) { 
         if (data.hasOwnProperty(propertyName)) { 
          propertyValue = data[propertyName]; 
          if ($.isFunction(propertyValue)) { 
           dataToSend[propertyName] = propertyValue(); 
          } else { 
           dataToSend[propertyName] = propertyValue; 
          } 
         } 
        }