Sajaxsource parameter, the value is the URL. The table sends an AJAX request to fetch the data from the server side. The data returned on the server side should be a JSON string that can be converted to a JSON object. This string must be in strict accordance with JSON format requirements. Otherwise there will be an error. The data object's key for this object should be "Aadata", for example:
JS Code:
{
"Aadata":
{
"ColumnA": "Valuea",
"COLUMNB": "Valueb",
...
}
}
The Bserverside parameter, set to True, indicates that data is processed using the server side. When sorting, it is directly to the background to query the data, directly displayed, will not be in the front of the sorting operation.
The Fnserverdata parameter, which is used to customize the function, instead of the default function of the DataTables plug-in to query data from the server side. The default functions are as follows:
Original reference from Webmaster network: http://www.software8.co/wzjs/jquery/3314.html
JS Code:
/**
* @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 is called on completion of the
* process that would 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 is not parsed. This is caused by a JSON formatting error. ");
}
}
});
},
We can use this parameter to customize the AJAX request, or we can manipulate the acquired data. For example:
Server-side returns the data object of the table, without using "aadata" as the key of the data, we can add "aadata" key to the data in our defined callback function.
Fnserverparams parameter, used to send additional data to the server. For example:
JS Code:
$ (' #example '). DataTable ({
"Bprocessing": true,
"Bserverside": true,
"Sajaxsource": "scripts/server_processing.php",
' Fnserverparams ': function (aodata) {
Aodata.push ({"Name": "More_data", "Value": "My_value"});
}
});