postData没有传递任何参数! [英] postData not passing any parameters!

查看:247
本文介绍了postData没有传递任何参数!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不到任何参数值在Firebug中传递给服务器.这是代码.

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$="BuyBackDownloadBtn"]').show();
              }
            },
            serializeGridData: function (data){ 
               return $.toJSON(data);   
            }
        });//end of jQuery("#BuyBackGrid").jqGrid()

}//BuyBackGridInit() End

谢谢

A

推荐答案

您当前serializeGridData的实现只需从中删除所有函数参数.因此,您应该在serializeGridData内扩展data参数,而不是使用postData.另一种方法是将serializeGridData修改为以下内容:

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);
}

在上面的代码中,我们枚举了所有属性并显式调用了所有函数.此外,我更喜欢使用 json2.js 中的JSON.stringify函数.该功能将在许多Web浏览器中本地实现.

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.

请在此处查看演示.

这篇关于postData没有传递任何参数!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆