Get extra field sent by server side script
Get extra field sent by server side script
karimmtlc
Posts: 8Questions: 3Answers: 0
Hi,
I am using server side processing with jquery datatables 1.10. I am able to add some fields to the json that I am sending to the client.
Now I need to get those extra fields that added.
I found that there was a solution for this in legacy datatables which does not work for me. Could you please show how to do it in 1.10?
Here is how my code looks like:
serverSide: true,
ajax: my_server_side_script_url,
deferLoading: $("#total_records").val(),
"fnServerData": function ( sSource, aoData, fnCallback ) {
console.log(sSource);
$.getJSON( sSource, aoData, function (json) {
console.log(json.myextrafield);
fnCallback(json);
} );
},
the console.log(sSource) result is null and the script does not get the call.
Thanks
This discussion has been closed.
Answers
See the
ajax.data
reference documentation and this example.Allan
Hi Allan,
The server scripts send an additional field in the json returned from the server, and I want to use that field in js.
Here is what is returned from the server:
"draw":"6","recordsTotal":20,"recordsFiltered":20,"data":[[...]],"extra_field1":4,"extra_field2":24}
I want to be able to use the values 4 and 24 of extra fields.
The link that you sent does the other way when you send extra data from js to the server.
Am I wrong?
Sorry - I misunderstood. Use either the
xhr
event orajax.dataSrc
option to access this data. The event is the one I would recommend.Allan
Hi Allan,
xhr works perfectly for me.
Thanks a lot