aoData is null

aoData is null

ruzzruzz Posts: 49Questions: 0Answers: 0
edited August 2010 in General
Hi all,
What I am trying to do, is pass a param to my webservice (which in the bad old days would have been something like server.com/blah.ext?param=value) Seems I need to use fnServerData and insert an object and push it onto aoData - right? Basically, during initialisation, I have this:

[code]
oTableHistory = $j('#table_history').dataTable( {
"sAjaxSource": "/Report_WS.asmx/GetCustomerDocumentHistoryJSON"
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "something": myvalue } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json)
} );
},

[/code]

It's the aoData.push which fails because aoData is null. Debugging I can see that the aoData buried somewhere in oSettings is an object (i.e. valid) but not here in this context.

I should point out, this is a second dataTable on this page - but I'm pretty sure there are no "clashes" (and besides, the first is functioning fine).

any help much appreciated!

ruzz

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    When using fnServerData without server-side processing, the second parameter passed to fnServerData is currently null. It's say that this is a bug and should in fact be an empty array. I'll fix this in the next release of DataTables. For now either just create your own array:

    [code]
    oTableHistory = $j('#table_history').dataTable( {
    "sAjaxSource": "/Report_WS.asmx/GetCustomerDocumentHistoryJSON"
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    $.getJSON( sSource, [ {"name": "something", "value": "myvalue"} ], function (json) {
    fnCallback(json)
    } );
    },
    [/code]
    or you can change the line in DataTables:

    [code]
    oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, null, function(json) {
    [/code]
    to

    [code]
    oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, [], function(json) {
    [/code]
    Allan
  • ruzzruzz Posts: 49Questions: 0Answers: 0
    Thanks for the rapid response, Allan.

    However, it didn't work. Here's the code now:

    [code]
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    $j.getJSON( sSource, [{ "customerDocumentTfsId" : "1v1" }], function (json) {
    fnCallback(json)
    } );
    [/code]

    Firebug says:

    http://127.0.0.1/Report_WS.asmx/GetCustomerDocumentHistoryJSON?undefined=undefined

    and, trimming off the fat from the FB Response tab: Missing parameter: customerDocumentTfsId

    Any ideas?
    TIA

    ruzz
  • ruzzruzz Posts: 49Questions: 0Answers: 0
    ah... I get it, the ajax call is looking for an extra level of indirection (a name/value pair whose names are "name" and "value")

    [{"name" : "customerDocumentTfsId", "value" : "1v1" }]

    and NOT

    [{"customerDocumentTfsId" : "1v1" }]

    Solved! Thanks again Allan.
    ruzz
This discussion has been closed.