javascript - How to send form data along with jQuery DataTables data in server-side processing mode -
i trying post form data without success , data couldn't loaded.
how can pass form data array , single textbox, combobox, etc. fnserverdata
?
table_obj = $('#group-table').datatable({ "sajaxsource": "url goes here", fnserverdata: function(ssource, aodata, fncallback,osettings) { osettings.jqxhr = $.ajax( { "datatype": 'json', "type": "post", "url": ssource+'?'+$.param(aodata), "data": $("#frm").serializearray(), "success": fncallback } ); }, aasorting: [[ 1, "desc" ]], bprocessing: true, bserverside: true, processing : true, columndefs: [{ 'targets': 0, 'searchable':false, 'orderable':false, 'classname': 'dt-body-center', 'render': function (data, type, full, meta){ return '<label><input type="checkbox" name="user_id[]" value="' + $('<div/>').text(data).html() + '"></label>'; } }], rowcallback: function(row, data, dataindex){ // if row id 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', });
solution 1
replace this:
$('#group-table').datatable({ "sajaxsource": "url goes here", fnserverdata: function(ssource, aodata, fncallback,osettings) { osettings.jqxhr = $.ajax( { "datatype": 'json', "type": "post", "url": ssource+'?'+$.param(aodata), "data": $("#frm").serializearray(), "success": fncallback } ); },
with:
$('#group-table').datatable({ "ajax": { "url": "url goes here", "type": "post", "data": function(d){ d.form = $("#frm").serializearray(); } },
your form data in form
parameter array of objects parameters name
, value
, below json representation:
"form": [{"name":"param1","value":"val1"},{"name":"param2","value":"val2"}]
solution 2
if want have form data name/value pairs, see this jsfiddle example of alternative solution.
notes
there checkboxes in data table. solution above not work form elements in data table, because datatable removes non-visible nodes dom.
Comments
Post a Comment