DataTables not getting populated by Rest services

DataTables not getting populated by Rest services

Beena_AroraBeena_Arora Posts: 1Questions: 0Answers: 0
edited January 2013 in DataTables 1.8
Hi
I have a datatable wherein the ajax source is Java rest webservice. The webservice is returning me a json object as below:
[code]
[{"Name":"name0","Path":"Path0"},{"Name":"name1","Path":"Path1"}]
[/code]

The script code is as below
[code]
$(document).ready(function () {

var oTable = $('#myDataTable').dataTable({

"sAjaxSource": "http://localhost:8080/api/store/masters",
"sAjaxDataProp": "",
"aoColumns": [{ "mData": "Name" }, { "mData": "Path"}]
});
[/code]

The server code is being called and it returns the json object but somehow the data table is not populating it. I would appreciate any help.

Thanks

Replies

  • aalbertiaalberti Posts: 3Questions: 0Answers: 0
    edited January 2013
    I'll answer you as it seems a json problem.....

    In my case I have something like this (in PHP):

    [code]
    $sEcho = $this->getRequest()->getParam("sEcho");
    $data = array(array("name0","Path0"),array("name1","Path1"));

    $response = array(
    "iTotalRecords" =>Whatever ,
    "iTotalDisplayRecords" => Whatever,
    "sEcho" => intval($sEcho),
    "aaData" => $data
    );
    $this -> _helper -> json($response);
    [/code]

    Hope it helps!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    iTotalRecords etc is only needed when you are using server-side processing, which it appears Beena_Arora is not doing.

    It should work, but my guess is that the browser is blocking a cross domain / port request. You might need to implement CORS or JSONP on the server, but it is impossible to say exactly what the issue is without a link to a test case.

    Allan
This discussion has been closed.