1
0
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:
Allan Jardine 2011-11-09 08:50:30 +00:00
parent 9639d4f485
commit 58f85fc601
2 changed files with 12 additions and 19 deletions

View File

@ -17,15 +17,7 @@
"bProcessing": true, "bProcessing": true,
"bServerSide": true, "bServerSide": true,
"sAjaxSource": "scripts/post.php", "sAjaxSource": "scripts/post.php",
"fnServerData": function ( sSource, aoData, fnCallback ) { "sServerMethod": "POST"
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} ); } );
} ); } );
</script> </script>
@ -37,7 +29,7 @@
</div> </div>
<h1>Preamble</h1> <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> <h1>Live example</h1>
<div id="dynamic"> <div id="dynamic">
@ -76,15 +68,7 @@
"bProcessing": true, "bProcessing": true,
"bServerSide": true, "bServerSide": true,
"sAjaxSource": "scripts/post.php", "sAjaxSource": "scripts/post.php",
"fnServerData": function ( sSource, aoData, fnCallback ) { "sServerMethod": "POST"
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} ); } );
} );</pre> } );</pre>
<style type="text/css"> <style type="text/css">

View File

@ -1320,6 +1320,7 @@
}, },
"dataType": "json", "dataType": "json",
"cache": false, "cache": false,
"type": settings.sServerMethod,
"error": function (xhr, error, thrown) { "error": function (xhr, error, thrown) {
if ( error == "parsererror" ) { if ( error == "parsererror" ) {
alert( "DataTables warning: JSON data from server could not be parsed. "+ alert( "DataTables warning: JSON data from server could not be parsed. "+
@ -1340,6 +1341,13 @@
*/ */
this.aoServerParams = []; 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 * Variable: fnFormatNumber
* Purpose: Format numbers for display * Purpose: Format numbers for display
@ -7011,6 +7019,7 @@
_fnMap( oSettings, oInit, "fnCookieCallback" ); _fnMap( oSettings, oInit, "fnCookieCallback" );
_fnMap( oSettings, oInit, "fnInitComplete" ); _fnMap( oSettings, oInit, "fnInitComplete" );
_fnMap( oSettings, oInit, "fnServerData" ); _fnMap( oSettings, oInit, "fnServerData" );
_fnMap( oSettings, oInit, "sServerMethod" );
_fnMap( oSettings, oInit, "fnFormatNumber" ); _fnMap( oSettings, oInit, "fnFormatNumber" );
_fnMap( oSettings, oInit, "aaSorting" ); _fnMap( oSettings, oInit, "aaSorting" );
_fnMap( oSettings, oInit, "aaSortingFixed" ); _fnMap( oSettings, oInit, "aaSortingFixed" );