JSON error - Doesnt support valid JSON?
JSON error - Doesnt support valid JSON?
I have the following database and code that I am trying to bind. I have just copied the Javascript Array example to try to get this to work. But I get the error
'DataTables warning (tableid = 'example': Requested unknown parameter '0' from data source for row 0.'
What am I doing wrong?
[code]
var test = [{ "ID": "1", "parentColumnSortID": "0", "description": "Precondition", "columnSortID": "1", "itemType": 0, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "2", "parentColumnSortID": "1", "description": "Goals", "columnSortID": "2", "itemType": 1, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "3", "parentColumnSortID": "2", "description": "Do in sequence", "columnSortID": "3", "itemType": 2, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "4", "parentColumnSortID": "3", "description": "", "columnSortID": "3.1", "itemType": 3, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "unit2", "parentColumnSortID": "3", "description": "", "columnSortID": "3.2", "itemType": 3, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "unit3", "parentColumnSortID": "3", "description": "", "columnSortID": "3.3", "itemType": 3, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null}];
$(document).ready(function () {
$('#dynamic').html('');
$('#example').dataTable({
"aaData": test,
"aoColumns": [
{ "sTitle": "ID" },
{ "sTitle": "parentColumnSortID" },
{ "sTitle": "description" },
{ "sTitle": "columnSortID", "sClass": "center" }
]
});
});
[/code]
'DataTables warning (tableid = 'example': Requested unknown parameter '0' from data source for row 0.'
What am I doing wrong?
[code]
var test = [{ "ID": "1", "parentColumnSortID": "0", "description": "Precondition", "columnSortID": "1", "itemType": 0, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "2", "parentColumnSortID": "1", "description": "Goals", "columnSortID": "2", "itemType": 1, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "3", "parentColumnSortID": "2", "description": "Do in sequence", "columnSortID": "3", "itemType": 2, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "4", "parentColumnSortID": "3", "description": "", "columnSortID": "3.1", "itemType": 3, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "unit2", "parentColumnSortID": "3", "description": "", "columnSortID": "3.2", "itemType": 3, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null },
{ "ID": "unit3", "parentColumnSortID": "3", "description": "", "columnSortID": "3.3", "itemType": 3, "agent": null, "warningsAndCautions": null, "notes": null, "potentialHumanFailures": null, "errorDescription": null, "potentialConsequences": null, "existingRiskControlMeasures": null, "performanceInfluencingFactors": null, "riskReductionMeasures": null, "pIFStatement": null, "pIFAssessment": null, "comments": null, "severityOfConsequences": null, "likelihoodOfError": null, "likelihoodOfRecovery": null, "rankScore": null, "logic": null, "qi": null, "hEPAProbability": null, "alternateProbability": null, "activity": null}];
$(document).ready(function () {
$('#dynamic').html('');
$('#example').dataTable({
"aaData": test,
"aoColumns": [
{ "sTitle": "ID" },
{ "sTitle": "parentColumnSortID" },
{ "sTitle": "description" },
{ "sTitle": "columnSortID", "sClass": "center" }
]
});
});
[/code]
This discussion has been closed.
Replies
[["unit2","3"," ","3.2"],["unit3","4"," ",3.3"]]
(or mDataProp, as Greg points out... depends which way is faster)
It's always a pain in the butt trying to figure out how to both store and read associative objects and arrays in JavaScript.
Judging by the error, you are asking for an element at an index (hence the '0') instead of at its name value. But without seeing the code that's actually processing the request, it's hard to say. Note that the error isn't saying it's invalid JSON, which it will normally do when not parsed correctly. So it's either the pattern of storing or the syntax of retrieving that's breaking.
[update: had another look at the JavaScript example; I would do it the way you're doing it, too. I'm not too helpful here. For what it's worth, I use named columns, too.]
Shot in the dark here, but I have a separate Ajax call on my page (not using DataTables) that uses an associative object, and it did not work unless I declared its type first:
[code]
var myObj = {};
myObj = {{"stuff":"things"},{"stuff":"otherthings"}};
[/code]
Might seem silly, but have you tried var test=[]; test=[stuff]?
[code]
"aoColumns": [
{ "mDataProp": "ID",
"sTitle": "ID" },
{
"mDataProp": "parentColumnSortID",
"sTitle": "parentColumnSortID" },
{
"mDataProp": "description",
"sTitle": "description" },
{
"mDataProp": "columnSortID",
"sTitle": "columnSortID", "sClass": "center" }
]
[/code]