Problem with DataTables server-side processing example

Problem with DataTables server-side processing example

sauravsaurav Posts: 3Questions: 0Answers: 0
edited December 2011 in General
Hi All,
I am trying to use the example code for "DataTables server-side processing example" in coldfusion
but it seems there in some problem with JSON data. Please take a look below for my code.

[quote]Page Name:dataTable5.cfm(This is the main page)[/quote]
[code]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">




DataTables live example


@import "media/css/demo_page.css"; @import "media/css/demo_table.css";










Rendering engine


Browser


Platform(s)


Engine version


CSS grade









$(document).ready(function() {
    $('#ajaxExample').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "ProcessData.cfm"
    } );
} );




[/code]

[quote]Page Name:ProcessData.cfm[/quote]
[code]


{
  "sEcho": 1,
  "iTotalRecords": "57",
  "iTotalDisplayRecords": "57",
  "aaData": [
    [
      "Gecko",
      "Firefox 1.0",
      "Win 98+ / OSX.2+",
      "1.7",
      "A"
    ],
    [
      "Gecko",
      "Firefox 1.5",
      "Win 98+ / OSX.2+",
      "1.8",
      "A"
    ],
    [
      "Gecko",
      "Firefox 2.0",
      "Win 98+ / OSX.2+",
      "1.8",
      "A"
    ],
    [
      "Gecko",
      "Firefox 3.0",
      "Win 2k+ / OSX.3+",
      "1.9",
      "A"
    ],
    [
      "Gecko",
      "Camino 1.0",
      "OSX.2+",
      "1.8",
      "A"
    ],
    [
      "Gecko",
      "Camino 1.5",
      "OSX.3+",
      "1.8",
      "A"
    ],
    [
      "Gecko",
      "Netscape 7.2",
      "Win 95+ / Mac OS 8.6-9.2",
      "1.7",
      "A"
    ],
    [
      "Gecko",
      "Netscape Browser 8",
      "Win 98SE+",
      "1.7",
      "A"
    ],
    [
      "Gecko",
      "Netscape Navigator 9",
      "Win 98+ / OSX.2+",
      "1.8",
      "A"
    ],
    [
      "Gecko",
      "Mozilla 1.0",
      "Win 95+ / OSX.1+",
      "1",
      "A"
    ]
  ]
}

[/code]

[quote]Error Message:DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error [/quote]

1>This is first time i am using dataTable and i am new to jquery also. So please help me.

Thanks,
Saurav

Replies

  • allanallan Posts: 63,258Questions: 1Answers: 10,421 Site admin
    Are you getting the CF tags in the JSON return? That would make it unparsable... Can you give us a link please? Is that what the JSON return looks like in Firebug?

    Allan
  • sauravsaurav Posts: 3Questions: 0Answers: 0
    edited December 2011
    No i am not getting any CF tags in JSON return. Following is what i get in response

    FireBug Details:
    [quote]
    Rsponse:
    [/quote]
    [code]

    {
    "sEcho": 1,
    "iTotalRecords": "57",
    "iTotalDisplayRecords": "57",
    "aaData": [
    [
    "Gecko",
    "Firefox 1.0",
    "Win 98+ / OSX.2+",
    "1.7",
    "A"
    ],
    [
    "Gecko",
    "Firefox 1.5",
    "Win 98+ / OSX.2+",
    "1.8",
    "A"
    ],
    [
    "Gecko",
    "Firefox 2.0",
    "Win 98+ / OSX.2+",
    "1.8",
    "A"
    ],
    [
    "Gecko",
    "Firefox 3.0",
    "Win 2k+ / OSX.3+",
    "1.9",
    "A"
    ],
    [
    "Gecko",
    "Camino 1.0",
    "OSX.2+",
    "1.8",
    "A"
    ],
    [
    "Gecko",
    "Camino 1.5",
    "OSX.3+",
    "1.8",
    "A"
    ],
    [
    "Gecko",
    "Netscape 7.2",
    "Win 95+ / Mac OS 8.6-9.2",
    "1.7",
    "A"
    ],
    [
    "Gecko",
    "Netscape Browser 8",
    "Win 98SE+",
    "1.7",
    "A"
    ],
    [
    "Gecko",
    "Netscape Navigator 9",
    "Win 98+ / OSX.2+",
    "1.8",
    "A"
    ],
    [
    "Gecko",
    "Mozilla 1.0",
    "Win 95+ / OSX.1+",
    "1",
    "A"
    ]
    ]
    }
    [/code]
  • allanallan Posts: 63,258Questions: 1Answers: 10,421 Site admin
    You've got a trailing comma after the last object which makes it not valid JSON. Try running it through http://jsonlint.com to check its formatting.

    Allan
  • sauravsaurav Posts: 3Questions: 0Answers: 0
    Thanks for your suggestion. It is working now. But still we need to inform
    http://datatables.net/release-datatables/examples/data_sources/server_side.html
    Because the example given there is not correct. I am getting [quote] Unexpected token [/quote]
    error when i am checking it in http://jsonlint.com/
  • allanallan Posts: 63,258Questions: 1Answers: 10,421 Site admin
    Are you using the validate plug-in for jQuery and is it up to date? That broke Ajax in the new versions for jQuery.

    Allan
This discussion has been closed.