开发者

postData not passing any parameters!

I'm not able to see any parameters value passing to server in firebug. Here is the code.


//BuyBackGridInit() start

function BuyBackGridInit(tabID){


        $('table[id$="'+tabID+'_BuyBackGrid"]').jqGrid({   
            url :'/Controls/Advertiser/BuyBackControlNew.ascx.ashx?action=getBuyBackData',
            datatype: 'json',
            mtype: 'POST', 
            height:'100%',
            width:'100%',
            colNames: result.colNamesData, 
            colModel: result.colModelData,
            postData: {
              advertiserID: function() { return $('#advertiser_id').text(); },
              CampaignsDdlSelectedValue: function() { return $('select[id$="CampaignDdl"] option:selected').val(); },
              startDate: function() { return $('input[id$="'+tabID+'_FromCalBuyBack_CalendarTbx"] ').val(); },
              endDate: function() { return $('input[id$="'+tabID+'_ToCalBuyBack_CalendarTbx"] ').val(); }
            },
            rowNum : 100,
            shrinkToFit :false,
            altRows: true,
            altclass:'altRow',
            autowidth: true,
            multiselect: true,
            gridComplete:function (){
              var recs = parseInt( $('table[id$="'+tabID+'_BuyBackGrid"]').getGridParam("records"),10);
              if (recs == 0){ 
                  $('div[id$="'+tabID+'_NoDataFoundBuyBackdiv"]').show();
                  $('input[id$="AddToCartBtn"]').hide();
                  $('input[id$="BuyBackDownloadBtn"]').hide();
              }
              else {
                  $('div[id$="'+tabID+'_NoDataFoundBuyBackdiv"]').hide();
                  $('input[id$="AddToCartBtn"]').show();
                  $('input[id$="BuyBackDownloadB开发者_StackOverflowtn"]').show();
              }
            },
            serializeGridData: function (data){ 
               return $.toJSON(data);   
            }
        });//end of jQuery("#BuyBackGrid").jqGrid()

}//BuyBackGridInit() End

Thanks,

A


You current implementation of serializeGridData just remove all functions parameters from the postData. So you should either extend data parameter inside of serializeGridData instead of the usage of postData. Another way is to modify serializeGridData to the following:

serializeGridData: function (data){
    var propertyName, propertyValue, dataToSend = {};
    for (propertyName in data) {
        if (data.hasOwnProperty(propertyName)) {
            propertyValue = data[propertyName];
            if ($.isFunction(propertyValue)) {
                dataToSend[propertyName] = propertyValue();
            } else {
                dataToSend[propertyName] = propertyValue
            }
        }
   }
   return JSON.stringify(dataToSend);
}

In the code above we enumerate all properties and call all functions explicitly. Moreover I prefer to use JSON.stringify function from json2.js. The function will be native implemented in many web browsers.

See the demo here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜