(Newbie) Datatables with JSON call

(Newbie) Datatables with JSON call

sp33dysp33dy Posts: 3Questions: 0Answers: 0
edited August 2013 in General
Can anyone help me? I've been trying for two days now and failing to get my Liferay JSON service to work with the DataTable I've configured. Basically, I can see my page call the JSON service, it get's data back, but the table data isn't getting populated. If I take the same JSON response and put into the javascript directly, all is well with the world.

Here's my javascript call:

[code]
$(document).ready(function(){$("#seasonsTable").dataTable({
bFilter:false,bJQueryUI:true,
sAjaxSource:"/api/jsonws/GFSL_DB_Services-portlet.club/get-club-ids-and-names",
aoColumns:[{sTitle:"Id",mData:"id"},{sTitle:"Name",mData:"name"}],
bServerSide:true,
})
});
[/code]

The JSON returned by server is:

[code]
{\"iTotalDisplayRecords\":\"9\",\"iTotalRecords\":\"9\",\"aaData\":[{\"id\":\"1\",\"name\":\"147 Snooker Club\"},{\"id\":\"2\",\"name\":\"Stoke Snooker Club\"},{\"id\":\"3\",\"name\":\"Stubbington Village Snooker Club\"},{\"id\":\"4\",\"name\":\"Mayfair\"},{\"id\":\"5\",\"name\":\"Hillpark Working Mens Club\"},{\"id\":\"6\",\"name\":\"Lee On Solent Workings Mens Club \"},{\"id\":\"7\",\"name\":\"HMS Collingwood\"},{\"id\":\"8\",\"name\":\"Queens Club\"},{\"id\":\"9\",\"name\":\"Gosport Trades Club\"}],\"sEcho\":1}
[/code]

As stated, if I put the above JSON string into the javascript above as "aaData" all is well with the world.

You can also see the problem here:

--link removed--

Any help would be appreciated.

Kind regards

Carl

Replies

  • sp33dysp33dy Posts: 3Questions: 0Answers: 0
    Ok, running the JSON call through JSONLint is showing me lots of errors, where I've converted the JSONObject (in Java) to string for the return. Trying to fix.
  • sp33dysp33dy Posts: 3Questions: 0Answers: 0
    Sorry peeps, after two days; JSONLint has shown me the error of my ways! Basically, i need to return the JSONObject rather than converting it to string and returning. Doh! how stupid of me.. All happy, thanks!
This discussion has been closed.