JSON parsing issues and sEcho prolbem

JSON parsing issues and sEcho prolbem

mschlozmschloz Posts: 4Questions: 0Answers: 0
edited August 2012 in General
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]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Can you give us a link to the page so we can see what is going wrong please?

    Allan
  • mschlozmschloz Posts: 4Questions: 0Answers: 0
    It is in a sandbox dev environment right now. I can see about getting a temp web page up. If I suppress the the errors to a javascript warning. It stops displaying the data to the table. But if I let the parsing errors through, it will display the data in the table after dismissing the error alter boxes.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Okay

    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
  • mschlozmschloz Posts: 4Questions: 0Answers: 0
    It turns out that someone tweaked fnReloadAjax function and it was not able to correctly request an update from the server side processing. Thank you for your help :) I will update when I have figure out the root cause.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited August 2012
    fnReloadAjax and server-side processing are mutually exclusive. As the documentation for fnReloadAjax says:

    > 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
  • mschlozmschloz Posts: 4Questions: 0Answers: 0
    You beat me to it. Exactly the issue. My table is updating and beautiful :-) Thank you for all the help.
This discussion has been closed.