JSON parsing issues and sEcho prolbem
JSON parsing issues and sEcho prolbem
I am having some major issues. I have enabled server side process and have properly formatted JSON data to give back to the table. I am get a JSON parsing error and I think it is due to sEcho being 0. When examining with Firebug nothing seems to being passed to my server side script from the data table. (no sEcho=balh), but bServerSide is set to true... Also, it will display the Test info received, and then complain about parse error... and it says sEcho is undefined index on the server side php script.
Here is the JSON data returned:
[code]
{
"sEcho":0,
"iTotalRecords":1,
"iTotalDisplayRecords":1,
"aaData":[
{"id":"1","appname":"Test","site":"","status":"00H:00M:00S","state":"0","enabled":"0","recStartDate":"","cmdRecording":"0"}
]
}
[/code]
Javascript code:
[code]
currentTable = $("#camDataTable").dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 25,
"sAjaxSource": '/inc/cameraData.php',
"aoColumns": [
{ "bVisible":false, "mDataProp": "id" },
{ "sWidth": "40%", "sTitle": "Name", "mDataProp": "appname" },
{ "sClass": "my_class", "bSortable": false, "sWidth": "35%", "fnRender": function(oObj){
//alert(oObj.aData.enabled);
$("#startbtn").attr('name', oObj.aData.id);
$("#stopbtn").attr('name', oObj.aData.id);
var name = document.getElementsByName(oObj.aData.id);
var start = name[0];
start.type = "button";
if(oObj.aData.enabled == 0){
start.value = "Start";
start.removeAttribute('readonly');
start.removeAttribute('size', '10px');
start.style.color = 'grey';
start.setAttribute('disabled', 'disabled');
name[1].value = "Stop";
name[1].removeAttribute('readonly');
name[1].removeAttribute('size', '10px');
name[1].style.color = 'grey';
name[1].setAttribute('disabled', 'disabled');
}
else{
if(oObj.aData.cmdRecording == oObj.aData.state){
if(oObj.aData.state == 1){
start.value = "Recording...";
start.type = "text";
start.setAttribute('readonly', 'readonly');
start.setAttribute('size', '10px');
start.style.color = 'orange';
start.setAttribute('disabled', 'disabled');
name[1].removeAttribute('disabled');
name[1].style.color = 'green';
}
else{
start.value = "Start";
start.removeAttribute('readonly');
start.removeAttribute('size', '10px');
start.style.color = 'green';
start.removeAttribute('disabled');
name[1].style.color = "grey";
name[1].disabled = true;
}
}
else{
start.value = "Start";
start.removeAttribute('readonly');
start.removeAttribute('size', '10px');
start.style.color = 'green';
start.removeAttribute('disabled');
name[1].type = "button";
name[1].value = "Stop";
name[1].style.color = "green";
name[1].disabled = false;
}
}
return $("#serviceButtons").html();
}
},
{ "sClass": "my_class", "bSortable": false, "sTitle": "Record Time", "sWidth": "25%", "fnRender": function(oObj){
var status = document.getElementById("status");
status.type = "button";
if(oObj.aData.status == 0){
status.value = "Error...";
status.type = "text";
status.style.color = 'red';
}
else{
status.value = oObj.aData.status;
status.style.color = 'green';
}
return $("#record").html();
}
},
{ "mDataProp": "site" }
],
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
var status = document.getElementById("status");
status.type = "button";
var id = aData.id;
$(nRow).attr('id', id );
var site = aData.site;
$(nRow).attr('value', site );
return nRow;
}
});
[/code]
Here is the JSON data returned:
[code]
{
"sEcho":0,
"iTotalRecords":1,
"iTotalDisplayRecords":1,
"aaData":[
{"id":"1","appname":"Test","site":"","status":"00H:00M:00S","state":"0","enabled":"0","recStartDate":"","cmdRecording":"0"}
]
}
[/code]
Javascript code:
[code]
currentTable = $("#camDataTable").dataTable({
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": 25,
"sAjaxSource": '/inc/cameraData.php',
"aoColumns": [
{ "bVisible":false, "mDataProp": "id" },
{ "sWidth": "40%", "sTitle": "Name", "mDataProp": "appname" },
{ "sClass": "my_class", "bSortable": false, "sWidth": "35%", "fnRender": function(oObj){
//alert(oObj.aData.enabled);
$("#startbtn").attr('name', oObj.aData.id);
$("#stopbtn").attr('name', oObj.aData.id);
var name = document.getElementsByName(oObj.aData.id);
var start = name[0];
start.type = "button";
if(oObj.aData.enabled == 0){
start.value = "Start";
start.removeAttribute('readonly');
start.removeAttribute('size', '10px');
start.style.color = 'grey';
start.setAttribute('disabled', 'disabled');
name[1].value = "Stop";
name[1].removeAttribute('readonly');
name[1].removeAttribute('size', '10px');
name[1].style.color = 'grey';
name[1].setAttribute('disabled', 'disabled');
}
else{
if(oObj.aData.cmdRecording == oObj.aData.state){
if(oObj.aData.state == 1){
start.value = "Recording...";
start.type = "text";
start.setAttribute('readonly', 'readonly');
start.setAttribute('size', '10px');
start.style.color = 'orange';
start.setAttribute('disabled', 'disabled');
name[1].removeAttribute('disabled');
name[1].style.color = 'green';
}
else{
start.value = "Start";
start.removeAttribute('readonly');
start.removeAttribute('size', '10px');
start.style.color = 'green';
start.removeAttribute('disabled');
name[1].style.color = "grey";
name[1].disabled = true;
}
}
else{
start.value = "Start";
start.removeAttribute('readonly');
start.removeAttribute('size', '10px');
start.style.color = 'green';
start.removeAttribute('disabled');
name[1].type = "button";
name[1].value = "Stop";
name[1].style.color = "green";
name[1].disabled = false;
}
}
return $("#serviceButtons").html();
}
},
{ "sClass": "my_class", "bSortable": false, "sTitle": "Record Time", "sWidth": "25%", "fnRender": function(oObj){
var status = document.getElementById("status");
status.type = "button";
if(oObj.aData.status == 0){
status.value = "Error...";
status.type = "text";
status.style.color = 'red';
}
else{
status.value = oObj.aData.status;
status.style.color = 'green';
}
return $("#record").html();
}
},
{ "mDataProp": "site" }
],
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
var status = document.getElementById("status");
status.type = "button";
var id = aData.id;
$(nRow).attr('id', id );
var site = aData.site;
$(nRow).attr('value', site );
return nRow;
}
});
[/code]
This discussion has been closed.
Replies
Allan
I would say that sEcho can never be 0 - it simply won't work. It is a counter for the number of draws and changes on every draw of the data: http://datatables.net/usage/server-side . So if you are getting 0 back from the server, then there is something going wrong with the server-side script.
Allan
> Note: To reload data when using server-side processing, just use the built-in API function fnDraw rather than this plug-in.
Possibly that is part of the issue?
Allan