sAjaxSource參數,值是url。table會發送ajax請求,從伺服器端擷取資料。伺服器端返回的資料應該是一個可以被轉換成JSON對象的JSON字串。這個字串必須嚴格符合JSON格式的要求。否則會出錯。該資料對象該對象的key應該是“aaData”,例如:Js代碼: { "aaData": { "columnA":"valueA", "columnB":"valueB", ... } } bServerSide參數,設定成true,表示使用伺服器端處理資料。當排序時,會直接到後台查詢資料,直接顯示,不會在前端進行排序操作。fnServerData參數,用來自訂函數,代替DataTables外掛程式預設的從伺服器端查詢資料的函數。預設的函數如下:Js代碼: /** * @param {string} sSource HTTP source to obtain the data from (sAjaxSource) * @param {array} aoData A key/value pair object containing the data to send * to the server * @param {function} fnCallback to be called on completion of the data get * process that will draw the data on the page. * @param {object} oSettings DataTables settings object */ "fnServerData": function ( sUrl, aoData, fnCallback, oSettings ) { oSettings.jqXHR = $.ajax( { "url": sUrl, "data": aoData, "success": function (json) { if ( json.sError ) { oSettings.oApi._fnLog( oSettings, 0, json.sError ); } $(oSettings.oInstance).trigger('xhr', [oSettings, json]); fnCallback( json ); }, "dataType": "json", "cache": false, "type": oSettings.sServerMethod, "error": function (xhr, error, thrown) { if ( error == "parsererror" ) { oSettings.oApi._fnLog( oSettings, 0, "DataTables warning: JSON data from " + "server could not be parsed. This is caused by a JSON formatting error." ); } } }); }, 我們可以用這個參數來自訂ajax請求,也可以對擷取到的資料進行處理等操作。例如:伺服器端之返回表格的資料對象,沒有用“aaData”作為資料的key,我們就可以在我們定義的回呼函數裡面,給資料加上“aaData” key。 fnServerParams參數,用來發送額外的資料給伺服器。例如:Js代碼: $('#example').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "scripts/server_processing.php", "fnServerParams": function ( aoData ) { aoData.push( { "name": "more_data", "value": "my_value" } ); } });