Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery datatables ajax callback

Tags:

I am using jQuery DataTables and doing server-side data. I'm trying to call a function when the ajax call returns. I tried inserting this fnCallback2 which calls my function and the original function, but jQuery just throws an error (and doesn't tell me what the error is) and skips out.

$("#brands").dataTable( { "bServerSide" : true, "sAjaxSource" : "ajax.php", "fnServerData" : function(sSource, aoData, fnCallback) {     fnCallback2 = function(a,b,c){         fnCallback.call(a,b,c);         update_editable();     };     $.ajax( {         "dataType" : 'json',         "type" : "POST",         "url" : sSource,         "data" : aoData,         "success" : fnCallback2     });}}); 

I also tried adding the fnInitComplete parameter, but that only gets called the first time, not after subsequent pages.

"fnInitComplete": function(){ update_editable(); }, 

How do I correctly call my code after the ajax request so that the original callback gets called as well?

like image 244
Bob Baddeley Avatar asked Oct 05 '11 20:10

Bob Baddeley


1 Answers

Another option is to use the fnDrawCallback that is called after each draw event. Which will be done after every ajax request.

"fnDrawCallback" : function() {     update_editable(); } 
like image 199
dotjoe Avatar answered Sep 27 '22 23:09

dotjoe