Datatable Warning: Json data could not be parsed error
Datatable Warning: Json data could not be parsed error
sagar25_25
Posts: 10Questions: 0Answers: 0
I am trying send data from ym servlet to jsp. I am getting above error. Please let me know what is wrong in this....but could not find solution...
Data being passed from servlet :
{"iTotalRecords":"5","iTotalDisplayRecords":"5","aaData":[["test","browser","platform","version","grade"]]}
Jsp ajax code :
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "http://localhost:7001/basisCalculatorObjects.do",
"aoColumns": [
{ "mData": "name" },
{ "mData": "address" },
{ "mData": "town" },
{ "mData": "state" },
{ "mData": "zip" }]
} );
} );
Data being passed from servlet :
{"iTotalRecords":"5","iTotalDisplayRecords":"5","aaData":[["test","browser","platform","version","grade"]]}
Jsp ajax code :
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "http://localhost:7001/basisCalculatorObjects.do",
"aoColumns": [
{ "mData": "name" },
{ "mData": "address" },
{ "mData": "town" },
{ "mData": "state" },
{ "mData": "zip" }]
} );
} );
This discussion has been closed.
Replies
Allan
Below is my javascript array example code which works.
$(document).ready(function() { $('#demo').html( '' );
$('#example').dataTable( { "aaData": [
[ "Trident", "Internet Explorer 6.0", "Win 98+", 6, "A" ],
[ "Trident", "Internet Explorer 7.0", "Win XP SP2+", 7, "A" ]
],
"aoColumns": [ { "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" },
{ "sTitle": "Version", "sClass": "center" },
{ "sTitle": "Grade", "sClass": "center", "fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
if ( sReturn == "A" ) {
sReturn = "A"; }
return sReturn; } }
] } );
} );
but when i dynamically get value of aadata from server it is giving same json parser error. I have checked my json output is valid.
This is my jsp portion
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "http://localhost:7001/canada/internal/basisCalculatorObjects.do",
"aoColumns": [ { "sTitle": "Engine" },
{ "sTitle": "Browser" },
{ "sTitle": "Platform" },
{ "sTitle": "Version", "sClass": "center" },
{ "sTitle": "Grade", "sClass": "center", "fnRender": function(obj) {
var sReturn = obj.aData[ obj.iDataColumn ];
if ( sReturn == "A" ) {
sReturn = "A"; }
return sReturn; } }
] } );
} );
This is my json data
{"sEcho":1,"iTotalRecords":"57","iTotalDisplayRecords":"57","aaData":[["test","40","wilton",123,"11111"]]}
A link would be most useful or at least running it through the DataTables debugger.
Allan
my json data is below
{"sEcho":"1","iTotalRecords":3,"iTotalDisplayRecords":3,"aaData":[["Saurabh","Avon","Hartford"],["Saurabh","Avon","Hartford"],["Saurabh","Avon","Hartford"]]}
now the error i am getting is oinit.aaData.length is null or not an object jquery.datatables.js line 6720.
Result is still same no data on page.
my jsp code...
$.ajax({ type: "POST", url: "http://localhost:7001/canada/internal/basisCalculatorObjects.do",
contentType: "application/json; charset=utf-8", dataType: "json",
success: function(data) { $('#companies').dataTable({ "aaData": eval(data.d) }); } });
localhost:7001 is my local server code so that is correct.
However:
> eval(data.d)
What is data.d - is that your JSON from the server? In which case you are feeding it:
[code]
aaData: {"sEcho":1,"iTotalRecords":"57","iTotalDisplayRecords":"57","aaData":[["test","40","wilton",123,"11111"]]}
[/code]
which isn't right.
Allan
$("#companies").dataTable ajax call was not working for me. However in .ajax i noticed i am not getting sEcho value...so i am setting it as 1 in my action class.
This is how i am setting in server
jsonResponse.add("aaData", data);
response.setContentType("application/Json");
response.getWriter().print(jsonResponse.toString());
so in my jsp
$.ajax({ type: "POST", url: "http://localhost:7001/canada/internal/basisCalculatorObjects.do",
contentType: "application/json; charset=utf-8", dataType: "json",
success: function(data) { $('#companies').dataTable({ "aaData": data
});
});
should it be just data.....
$.ajax({ type: "POST", url: "http://localhost:7001/canada/internal/basisCalculatorObjects.do",
contentType: "application/json; charset=utf-8", dataType: "json",
success: function(data) { $('#companies').dataTable({ "aaData": data
});
});
now i am getting no data available in table.
the debugger code is ewuwac