using JQuery Datatables and all is going well.
I've worked out how to send addtional information from the client to the server. Now, I want to go back the other way.
So, how do I send extra information from the server to the client. I would have thought I could add an extra entry in the returned JSON and pull it out somewhere. One item I'd perhaps like to send back is how long the server took to handle the response. I can then show this information to the user.
Any help would be much appreciated. Thanks
I think you got quite everything right. You just need to attach the additional data server side in the JSON object and then get it in "fnServerData". You can add this code to the inizialization object:
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.getJSON( sSource, aoData, function (json) {
//Here you can do whatever you want with the additional data
console.dir(json);
//Call the standard callback to redraw the table
fnCallback(json);
} );
}
Server side you can add as many parameters as you want: Usually you have a json with 3 parameters "iTotalRecords" (total number of rows), "iTotalDisplayRecords" (Filtered total if you are using filters) and aaData (An associative array with the rows). If you add for example "iProcessingTime" (time it took to process server side) You could do:
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.getJSON( sSource, aoData, function (json) {
//take the processing time and put it in a div
$('#processingTime').html(json.iProcessingTime);
//pass the data to the standard callback and draw the table
fnCallback(json);
} );
}
Is this what you need?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With