json no loading

json no loading

arroarro Posts: 3Questions: 0Answers: 0
edited August 2010 in General
Hi,

I'm looking to see if I can use DataTables... So I´m trying to use the .getJSON. The Json I´m getting is valid according to JSONLint. I can see in Firebug that the it loads and I see the response (which I validated) However there is nothing visible in the DataTables, all I see is Processing.

[code]

$(document).ready(function () {
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/field/getFields",
"fnServerData": function (sSource, aoData, fnCallback) {
/* Add some extra data to the sender */
aoData.push({ "name": "more_data", "value": "my_value" });
$.getJSON(sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
});
}
});
});

[/code]

So I´m wondering what could be wrong, and how to debug ?

Regards
Arro

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The initialisation looks fine. What does your JSON data look like - can you post it here please?

    Allan
  • arroarro Posts: 3Questions: 0Answers: 0
    Hi here is the JSON response

    [code]
    {"page":1,"total":4,"rows":[{"id":"1000","cell":["1000","Vestur","Fj
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The JSON is providing the parameters that DataTables needs to work. The format needs to be as given here: http://datatables.net/usage/server-side

    You can see this in action using the server-side processing example and looking at the XHR's as they come through in Firebug.

    Allan
  • arroarro Posts: 3Questions: 0Answers: 0
    Hi allan,

    thanks for pointing this out to me, anyways I changed the JSON see

    [code]
    {
    "sEcho": 1,
    "iTotalRecords": 4,
    "iTotalDisplayRecords": 4,
    "aaData": [
    {
    "id": "1000",
    "cell": [
    "1000",
    "Vestur",
    "Fj
  • UPEngineerUPEngineer Posts: 93Questions: 0Answers: 1
    edited August 2010
    Looks like you your "id" and "cell" need to be in between the [ ].

    Here is an example of a valid JSON return from one of my projects as shown here.

    Get it to look like this and you will be good to go!

    [code]
    {
    "sEcho": 3,
    "iTotalRecords": 186,
    "iTotalDisplayRecords": 3,
    "aaData": [
    [
    "td 1",
    "td 2",
    "td 3",
    "td 4",
    "td 5"
    ],
    [
    "td 1",
    "td 2",
    "td 3",
    "td 4",
    "td 5"
    ],
    [
    "td 1",
    "td 2",
    "td 3",
    "td 4",
    "td 5"
    ]
    ]
    }
    [/code]
This discussion has been closed.