json.aaData is undefined
json.aaData is undefined
andrew.bishop
Posts: 6Questions: 0Answers: 0
Hi all: I'm having some trouble getting my table to load data dynamically. This is most likely due to my n00bness when it comes to JSON objects and AJAX calls in general, but I was hoping for some insight.
I have the following code as a script:
$('#Production').dataTable({
"sDom": '<"top"flp<"clear">>rt<"bottom"i<"clear">',
"bAutoWidth": false,
"bProcessing": true,
"sAjaxSource": 'includes/Complete.php'
});
And I have the following on the called page:
$aaData = array(10126, 10002253, 415);
echo json_encode($aaData);
The data on "Complete.php" is dummy data I'm using to test the functionality. I have 3 elements in the array returned for 3 columns it will be displayed in.
When I run the page with datatables on it, I get a JS error of json.aaData is undefined.
I'm using datatables 1.4.3 and jQuery 1.3.2
I have the following code as a script:
$('#Production').dataTable({
"sDom": '<"top"flp<"clear">>rt<"bottom"i<"clear">',
"bAutoWidth": false,
"bProcessing": true,
"sAjaxSource": 'includes/Complete.php'
});
And I have the following on the called page:
$aaData = array(10126, 10002253, 415);
echo json_encode($aaData);
The data on "Complete.php" is dummy data I'm using to test the functionality. I have 3 elements in the array returned for 3 columns it will be displayed in.
When I run the page with datatables on it, I get a JS error of json.aaData is undefined.
I'm using datatables 1.4.3 and jQuery 1.3.2
This discussion has been closed.
Replies
The Json format that DataTables expects is:
[code]
{ "aaData": [
[ 10126, 10002253, 415 ]
] }
[/code]
You can see this in the Json source demo - this is it's source file: http://datatables.net/examples/media/examples_support/json_source.txt
So basically you just need to wrap your data up in another array and an object :-) The reason for doing it this way is that it provides the option of passing back extra information to either DataTables of your own callback functions (DataTables only uses aaData, but the option is there for the future).
Hope this helps,
Allan
I have problem with loading (Firefox) only single row from aadata file?
{ "aaData": [
["AAA","BBB","CCC","2"]
] }
Is this a bug?
Regards
Adam
I have problem with importing data from csv with less then three rows?.
This work:
{ "aaData": [
["AAA","BBB","100","2"],
["AAA","BBB","100","2"],
["AAA","BBB","100","2"]
] }
and this don't work:
{ "aaData": [
["AAA","BBB","100","2"],
["AAA","BBB","100","2"]
] }
{ "aaData": [
["AAA","BBB","100","2"]
] }