0

I have a json rpc server that serves and rerurns json in the mode given including id results and jsonrpc keys ofa json string

{
jsonrpc: "2.0"
id: "1"
result: "{"iTotalDisplayRecords":"2","iTotalRecords":"2","aaData":   [["1","Kenya","Nairobi","0","34"],["2","USA","New York","70","38"]],"sEcho":0}"
}

now the problem comes in after the response comes in the web browser and datatables just displays loding data from server forever

i have tried tried adding

..."sAjaxDataProp":"",...

but that leads to a no matching rows found. I have used the same coe in the Rpc server as a cgi script and found that i get the desired output and the tables populate well. The json response from the script is as

{"iTotalDisplayRecords":"2","iTotalRecords":"2","aaData":[["1","Kenya","Nairobi","0","34"],["2","USA","New York","70","38"]],"sEcho":1}

I would like a way to tell datatables to only choose the result part of the jsonrpc request in order to display the returned data as expected.

here is the sending datapart in my javascript

oTable=$('#ip_data').dataTable( {
                            "bProcessing": true,
                             "bServerSide": true,
                             "bPaginate": true,
                             "bScrollCollpase": true,
                             "sScrollY": "200px",
                             "sAjaxSource": "/url",
                             "fnServerData": function (sSource, aoData, fnCallback, oSettings) {
                                aoData.push({"name":"method","value":"datatables"});
                                aoData.push({"name":"id","value":"1"});
                                oSettings.jqXHR = $.ajax({
                                    "dataType":"json",
                                    "type":"GET",
                                    "url":sSource,
                                    "data":aoData,
                                    "success":fnCallback
                                });//END OF AJAX                                                           
                    }//END OF FNSERVERDATA
            });//END OF DATATABLE
Gideon Maina
  • 849
  • 10
  • 25

1 Answers1

0

Firstly, use datatables 1.10 (and update your syntax!) https://datatables.net/upgrade/1.10-convert

Secondly, read this https://datatables.net/manual/server-side then read this https://datatables.net/reference/option/ajax

Your solution may end up looking something like

var oTable = $('#ip_data').DataTable( {
    "serverSide": true,
    "ajax": {
        "url": "/url",
        "data": {
            "method": "datatables",
            "id": "1",
        }
    },
});
ZenCodr
  • 1,176
  • 8
  • 12
  • By using console.log(json.result) i get the required response. Why is fnCallback not populating the table when i give it the argument of json.result like this "success": function(json) { console.log(json.result); fnCallback(json.result); Says that Cannot read property 'length' of undefined – Gideon Maina Jun 16 '14 at 06:53