Usage of fnServerData breaks ajax request

Usage of fnServerData breaks ajax request

alechkoalechko Posts: 2Questions: 0Answers: 0
edited June 2013 in General
Hey all,
I'm initializing datatable by:
[code]
var settings = {
...
'bProcessing' : TRUE,
'bServerSide' : TRUE,
'sAjaxSource' : url,
'sServerMethod' : 'POST',
...
};
var table = $(selector).dataTable(settings);
[/code]

and works great.
When trying to add some custom post variables using the example from http://datatables.net/examples/server_side/custom_vars.html
[code]
var settings = {...};
settings.fnServerData = function ( sSource, aoData, fnCallback ){
aoData.push( { "name": "more_data", "value": "my_value" } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
});
};
var table = $(selector).dataTable(settings);
[/code]
the ajax request breaks somewhere, and I get no POST request to my server-side callback.
what am I missing?
thanx.

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    You are using `$.getJSON(` so why would it make a POST request? :-). fnServerData overrides the DataTables ajax call - you make your own call.

    Allan
  • alechkoalechko Posts: 2Questions: 0Answers: 0
    Oh man, it's my bad... Was too tired to think of that yesterday :P
    Anyway, the working code is:
    [code]
    ...
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    aoData.push( { "name": "more_data", "value": "my_value" } );
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    ...
    [/code]
    Thanx man!
This discussion has been closed.