1
我正在使用Datatables進行服務器端處理。我能夠向服務器發送額外的參數,但是它們僅在第一次加載表時或由於過濾,排序等而重新加載表時發送。我希望將額外的參數發送到服務器每次我從選擇字段中選擇一個值。我如何實現這種行爲?提前致謝。數據表服務器端。異步發送額外參數
這是我的DataTable腳本
<script>
$(document).ready(function() {
$('#tabla').dataTable({
"sDom": '<"top"l>rt<"bottom"pi><"clear">',
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"sAjaxSource": "server_side3.php?action=table_data",
"bDeferRender": true,
"aLengthMenu": [10, 25, 40],
"contentType": "application/json; charset=utf-8",
"dataType": "json",
"fnServerParams": function (aoData) {
aoData.push({ "name": "year", "value": $("#year option:selected").text() });
},
language: {
url: '//cdn.datatables.net/plug-ins/380cb78f450/i18n/Spanish.json'
}
}).columnFilter();
});
</script>
我也試過用這段代碼:
"fnServerData": function (sSource, aoData, fnCallback) {
/* Add some extra data to the sender */
aoData.push({ "name": "year", "value": $("#year option:selected").text() });
$.getJSON(sSource, aoData, function (json) {
fnCallback(json)
});
而且我的HTML
<select id="year">
<?php
echo '<option value="'.date(Y).' selected">'.date(Y).'</option>';
for ($i=2005; $i < date(Y) ; $i++) {
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
我想你想使用fnServerData。看看我的答案在這裏:http://stackoverflow.com/questions/21704398/understanding-fnserverdata-in-datatables – mainguy 2014-11-09 10:53:15