DataTables not getting populated by Rest services
DataTables not getting populated by Rest services
Beena_Arora
Posts: 1Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
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!
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