ajax call with different aoData than on initialization

ajax call with different aoData than on initialization

alexxBalexxB Posts: 2Questions: 0Answers: 0
edited November 2013 in General
hi,

i try to do another ajax call, when an item in a tree is clicked. if that click happens i need to repeat the original ajax call, but with different custom data (aoData).
but as soon as a fnDraw is invoked, i allways get my original ajax call executed, that was used on table initialization.

i set up a data-table using ajax calls.
i setup the table like this
[code]
var oTable = $('#assetTable').dataTable( {
"bServerSide": true,
"sAjaxSource": getAssetDataUrl
.....
[/code]

my fnReloadAjax looks mostly like here: http://datatables.net/plug-ins/api#fnReloadAjax, but i added my new parameters
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
{
if ( sNewSource !== undefined && sNewSource !== null ) {
oSettings.sAjaxSource = sNewSource;
}

// that would be wrong for me so commented out
// Server-side processing should just call fnDraw
// if ( oSettings.oFeatures.bServerSide ) {
// this.fnDraw();
// return;
// }

this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
var iStart = oSettings._iDisplayStart;

var aoData = [ { "name": "externalId", "value": externalId } ];


this.oApi._fnServerParams( oSettings, aoData );

oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, aoData, function(json) {
/* Clear the old information from the table */
that.oApi._fnClearTable( oSettings );
....
[/code]

this works fine so far, i can see the correct call to the ajax file is done, with the correct "externalId" value i need. the response is correct as well.
but unfortunately the data is not displayed yet.
as soon as a fnDraw is called later in the function, another ajax call is done with the values from the initialization - and there with the WRONG externalId of course.

is there some way around that?

thanks for help on this fantastic plugin

cheers

alex

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It sounds you are using server-side processing, but you've commented out the part of fnReloadAjax that makes that plug-in work with server-side processing :-).

    Are you just wanting to send a different parameter to the server on each result? If so, use fnServerParams and then call fnDraw whenever you want to redraw the table. - much easier!

    Allan
  • alexxBalexxB Posts: 2Questions: 0Answers: 0
    yes yes, i use server side processing, but not only. i needed that functionality to change a parameter for the ajax call on demand.
    since i am quite new to web stuff i struggled a bit with the usage; i had already tried using fnServerParams but i was too dumb then ;)

    all working now and running like a charm!

    thanks for the help and this great plugin!

    cheers

    alex
This discussion has been closed.