将DataTables中的aoData数组与serlitzed表单相结合

时间:2015-07-18 05:26:39

标签: php jquery datatables

我正在使用jquery数据表,并希望使用jquery将aoData与表单序列化数据结合起来。

fnServerData: function(sSource, aoData, fnCallback,oSettings) {
                    aoData.concat( $("#frm").serializeArray());
                    console.log(aoData);
                    $.ajax( {
                                                "dataType": 'json',
                                                "type": "POST",
                                                "url": 'sSource',
                                                "data": aoData,
                                                "success": fnCallback
                                              } );

}

但是不会合并并仅返回数据表的数组响应。

你能帮我解决一下这个问题吗?

由于

3 个答案:

答案 0 :(得分:0)

请尝试使用此代码告诉我

fnServerData: function(sSource, aoData, fnCallback,oSettings) {
                        $.ajax( {
                                  "dataType": 'json',
                                  "type": "POST",
                                  "url": 'sSource',
                                  "data": $.merge(aoData, 
                                          $("#frm").serializeArray()),
                                  "success": fnCallback
                                                  } );

                                }

答案 1 :(得分:0)

 table_obj = $('#group-table').dataTable({
                "sAjaxSource": "URL Goes HEre",
                fnServerData: function(sSource, aoData, fnCallback,oSettings) {

                        aoData.push( $("#frm").serializeObject() );

                        console.log(aoData);
                        $.ajax( {
                                                    "dataType": 'json',
                                                    "type": "POST",
                                                    "url": sSource,
                                                    "data": aoData,
                                                    "success": fnCallback
                                                  } );

                },
                aaSorting: [[ 1, "desc" ]],
                bProcessing: true,
                bServerSide: true,
                processing : true,


                rowCallback: function(row, data, dataIndex){
                    // If row ID is in list of selected row IDs
                    if($.inArray(data[0], rows_selected) !== -1){
                       $(row).find('input[type="checkbox"]').prop('checked', true);
                       $(row).addClass('selected');
                    }
                },

                iDisplayLength: '50',
            });

答案 2 :(得分:-1)

table_obj = $('#group-table').dataTable({
                "sAjaxSource": "URL Goes HEre",
                fnServerData: function(sSource, aoData, fnCallback,oSettings) {
                        $.ajax( {
                                                    "dataType": 'json',
                                                    "type": "POST",
                                                    "url": sSource,
                                                    "data": $.merge(aoData, $("#frm").serializeArray()),
                                                    "success": fnCallback
                                                  } );

                },
                aaSorting: [[ 1, "desc" ]],
                bProcessing: true,
                bServerSide: true,
                processing : true,


                rowCallback: function(row, data, dataIndex){
                    // If row ID is in list of selected row IDs
                    if($.inArray(data[0], rows_selected) !== -1){
                       $(row).find('input[type="checkbox"]').prop('checked', true);
                       $(row).addClass('selected');
                    }
                },

                iDisplayLength: '50',
            });