Ajax calls not working with json response
Ajax calls not working with json response
Hi,
I am new to datatables and I am trying to populate my table with ajax call to java back end which returns json.
I am not sure if it is a problem with my server side or client side code - see below:
client-side:
$(document).ready(function(){
var oTable = $('#example').dataTable(
{
"bLengthChange" : false,
"bPaginate" : false,
"sScrollY" : "350px",
"bScrollCollapse": true,
"bJQueryUI": true,
"bProcessing" : true,
"aAjaxSource" : '/getData.json'
});
});
Server-side is using jackson mapper to return json to client. Part if the json response is as follows:
{"aaData":[{"genericId":12235565,"Id":"1111","code":"testcode"},{"genericId":12982675,"Id":"2222","code":"testcode"}]}
The function is definately being accessed as I debugged with a simple alert - so the table should be populating.
Please assist,
Thanks in advance
I am new to datatables and I am trying to populate my table with ajax call to java back end which returns json.
I am not sure if it is a problem with my server side or client side code - see below:
client-side:
$(document).ready(function(){
var oTable = $('#example').dataTable(
{
"bLengthChange" : false,
"bPaginate" : false,
"sScrollY" : "350px",
"bScrollCollapse": true,
"bJQueryUI": true,
"bProcessing" : true,
"aAjaxSource" : '/getData.json'
});
});
Server-side is using jackson mapper to return json to client. Part if the json response is as follows:
{"aaData":[{"genericId":12235565,"Id":"1111","code":"testcode"},{"genericId":12982675,"Id":"2222","code":"testcode"}]}
The function is definately being accessed as I debugged with a simple alert - so the table should be populating.
Please assist,
Thanks in advance
This discussion has been closed.
Replies
{"sEcho":1,"iTotalRecords":4,"iTotalDisplayRecords":4, "aaData":[["genericId":12235565,"Id":"1111","code":"testcode"],["genericId":12982675,"Id":"2222","code":"testcode"]]}
front end code is :
$(document).ready(function() {
alert("Got into function");
var oTable = $('#example').dataTable( {
"bProcessing": true,
//"bServerSide": true,
"sAjaxSource" : '/getData.json'
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );
This is still not populating my datatable on loading of page.
Please help as I am not seeing where the issue is - based on examples online I have sufficient code in jsp and the structure of my json being returned is ok.