Access JSON response object

Access JSON response object

diondudiondu Posts: 24Questions: 0Answers: 0
edited February 2012 in General
My JSON response has this structure.
[code]{
sEcho:1,
iTotalRecords:1300,
iTotalDisplayRecords:50,
aaData: [...] ,
sqlDataTables: "SELECT ... FROM ... WHERE ...."
}
[/code]

How can I acess the "sqlDataTables" variable in my Javascript code?

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Two ways - use fnServerData to provide your own Ajax call or listen for the 'xhr' event ( http://datatables.net/docs/DataTables/1.9.beta.3/#xhr ).

    The latter method is how my examples update the JSON return from the server:

    [code]

    $(document).ready( function () {
    if ( $.fn.dataTableSettings.length >= 1 ) {
    $('#example').dataTable().bind('xhr', function ( e, oSettings ) {
    var n = document.getElementById('latest_xhr');
    n.innerHTML = JSON.stringify(
    JSON.parse(oSettings.jqXHR.responseText), null, 2
    );
    n.className = "brush: js;"
    SyntaxHighlighter.highlight({}, n);
    } );
    }
    } );
    [/code]

    Allan
This discussion has been closed.