mirror of
https://github.com/DataTables/DataTables.git
synced 2025-03-15 16:29:16 +01:00
New: Add "sServerMethod" initialisation option to make it easy to change from GET to POST for server-side requests. Needing to supply a custom fnServerData just to get POST was a bit of a pain - this is now no longer needed. In theory fnServerData should generally not be needed now (with fnServerParams, mDataProp and this new parameter making set up much more flexible).
This commit is contained in:
parent
9639d4f485
commit
58f85fc601
@ -17,15 +17,7 @@
|
||||
"bProcessing": true,
|
||||
"bServerSide": true,
|
||||
"sAjaxSource": "scripts/post.php",
|
||||
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
||||
$.ajax( {
|
||||
"dataType": 'json',
|
||||
"type": "POST",
|
||||
"url": sSource,
|
||||
"data": aoData,
|
||||
"success": fnCallback
|
||||
} );
|
||||
}
|
||||
"sServerMethod": "POST"
|
||||
} );
|
||||
} );
|
||||
</script>
|
||||
@ -37,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
<h1>Preamble</h1>
|
||||
<p>The default HTTP method that DataTables uses to get data from the server-side if GET, however, there are times when you may wish to use POST. This is very easy using the fnServerData() initialisation parameter, as shown in this example.</p>
|
||||
<p>The default HTTP method that DataTables uses to get data from the server-side if GET, however, there are times when you may wish to use POST. This is very easy using the sServerMethod initialisation parameter, which is simply set to the HTTP method that you want to use - the default is 'GET' and this example shows 'POST' being used.</p>
|
||||
|
||||
<h1>Live example</h1>
|
||||
<div id="dynamic">
|
||||
@ -76,15 +68,7 @@
|
||||
"bProcessing": true,
|
||||
"bServerSide": true,
|
||||
"sAjaxSource": "scripts/post.php",
|
||||
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
||||
$.ajax( {
|
||||
"dataType": 'json',
|
||||
"type": "POST",
|
||||
"url": sSource,
|
||||
"data": aoData,
|
||||
"success": fnCallback
|
||||
} );
|
||||
}
|
||||
"sServerMethod": "POST"
|
||||
} );
|
||||
} );</pre>
|
||||
<style type="text/css">
|
||||
|
9
media/js/jquery.dataTables.js
vendored
9
media/js/jquery.dataTables.js
vendored
@ -1320,6 +1320,7 @@
|
||||
},
|
||||
"dataType": "json",
|
||||
"cache": false,
|
||||
"type": settings.sServerMethod,
|
||||
"error": function (xhr, error, thrown) {
|
||||
if ( error == "parsererror" ) {
|
||||
alert( "DataTables warning: JSON data from server could not be parsed. "+
|
||||
@ -1340,6 +1341,13 @@
|
||||
*/
|
||||
this.aoServerParams = [];
|
||||
|
||||
/*
|
||||
* Variable: sServerType
|
||||
* Purpose: Send the XHR HTTP method - GET or POST (could be PUT or DELETE if required)
|
||||
* Scope: jQuery.dataTable.classSettings
|
||||
*/
|
||||
this.sServerMethod = "GET";
|
||||
|
||||
/*
|
||||
* Variable: fnFormatNumber
|
||||
* Purpose: Format numbers for display
|
||||
@ -7011,6 +7019,7 @@
|
||||
_fnMap( oSettings, oInit, "fnCookieCallback" );
|
||||
_fnMap( oSettings, oInit, "fnInitComplete" );
|
||||
_fnMap( oSettings, oInit, "fnServerData" );
|
||||
_fnMap( oSettings, oInit, "sServerMethod" );
|
||||
_fnMap( oSettings, oInit, "fnFormatNumber" );
|
||||
_fnMap( oSettings, oInit, "aaSorting" );
|
||||
_fnMap( oSettings, oInit, "aaSortingFixed" );
|
||||
|
Loading…
x
Reference in New Issue
Block a user