Get extra field sent by server side script

Get extra field sent by server side script

karimmtlckarimmtlc 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

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    See the ajax.data reference documentation and this example.

    Allan

  • karimmtlckarimmtlc Posts: 8Questions: 3Answers: 0

    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?

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Sorry - I misunderstood. Use either the xhr event or ajax.dataSrc option to access this data. The event is the one I would recommend.

    Allan

  • karimmtlckarimmtlc Posts: 8Questions: 3Answers: 0

    Hi Allan,

    xhr works perfectly for me.

    Thanks a lot

This discussion has been closed.