I am Using DataTable 1.7.5 along with JQuery-1.7.1.min.js and getting a JSON parsing ERROR. While looking through several Online forums it was suggested to upgrade the validator plugin of JQuery-1.5.1.min.js but nothing about the validator of JQuery-1.7.1.min.js.Does any body has any suggestion regarding this issue ?
Table HTML:
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" >
<thead>
<tr>
<th>#</th>
<th></th>
<th>Name</th>
<th>Shpr</th>
<th>Org</th>
<th>Cne</th>
<th>Dest</th>
<th>Dep Dt</th>
<th>LR No</th>
<th>Asset No</th>
<th>Curr Dt</th>
<th>Spd km/h</th>
<th>Waypoint1</th>
<th>Waypoint2</th>
<th>SDA</th>
<th>DETA</th>
<th>AMC</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Javascript:
var oTable = $('#example').dataTable({
"aLengthMenu" : [[-1, 10, 25, 50, 100], ["All", 10, 25, 50, 100]],
"iDisplayLength" : -1,
"bProcessing": true,
"bJQueryUI": true,
"bAutoWidth": false,
//"sScrollY": "300px",
"sPaginationType": "full_numbers",
"sAjaxSource": "ReportAction.do?process=home",
"bDeferRender":true,
"sDom": 'T<"clear"><"H"lfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "<%=localrequestedURL %>media/swf/copy_csv_xls_pdf.swf"
}
});
JSON Data:
result = session.createSQLQuery(sql_homepage).list();
String final_data = gson.toJson(result);
final_message = "{\"aaData\":"+final_data+"}";
1.The variable sql_homepage refers to a select query to the database. 2.The variable final_message is passed to the action class which passes the data to the JSP.
I had the same problem and it was from an invisible character that got saved to the database. It is best to use a json validator to see where your error is. I used this one: http://www.freeformatter.com/json-validator.html and this one http://jsonformatter.curiousconcept.com/
datatables is super finickey about the JSON it will parse. I has to be 100% perfect and I ended up needing to create a php function to make the JSON object string instead of just using php function json_encode