fnDraw() and "Processing...."

fnDraw() and "Processing...."

shamelessshameless Posts: 31Questions: 0Answers: 0
edited February 2010 in General
Alan,

I am refreshing a table's AJAX / JSON via oTable.fnDraw() . The ""Processing...." message persists.

This only occurs after the "refresh", not the initial successful AJAX load.

Any ideas as to why this would be?

Shameless

Replies

  • allanallan Posts: 63,407Questions: 1Answers: 10,452 Site admin
    Hi Shameless,

    Sounds like your JSON that you are reloading is not valid. If you run it through http://jsonlint.com is it okay? Failing that, any JS errors or any other indications of anything?

    Regards,
    Allan
  • shamelessshameless Posts: 31Questions: 0Answers: 0
    Hi, again, Alan.

    This is the JSON that "succeeds" upon initialization:
    [code]
    {"sEcho": 1,"iTotalRecords": 2,"iTotalDisplayRecords": 2,"aaData": [ [ "8","","25","February 24, 2010 - 11:21 AM","February 26, 2010 - 02:41 PM","1.00","Yes","11","71957","March 3, 2010 - 11:21 AM"], [ "11","","1000","February 26, 2010 - 02:18 PM","February 26, 2010 - 02:41 PM","1.00","Yes","11","71957","March 5, 2010 - 02:18 PM"] ]}
    [/code]

    JSLint: "JSON: good."

    And this is the JSON after attempting a re-load via fnDraw() and getting the persistent "Processing...." status and no change in the loaded rows:
    [code]
    {"sEcho": 1,"iTotalRecords": 2,"iTotalDisplayRecords": 2,"aaData": [ [ "8","","25","February 24, 2010 - 11:21 AM","February 26, 2010 - 02:41 PM","1.00","Yes","11","71957","March 3, 2010 - 11:21 AM"], [ "11","","1000","February 26, 2010 - 02:18 PM","February 26, 2010 - 02:41 PM","1.00","Yes","11","71957","March 5, 2010 - 02:18 PM"] ]}
    [/code]

    JSLint: "JSON: good."

    (This is just one sample of four DataTables that all exhibit the same behaviour.)

    They appear to be the identical results to me and I have no idea why one would load successfully and dispense with the "Processing...." message as expected and the subsequent loads would NOT load and keep "Processing..."

    BTW, is there anyway to see the results of the aaData via Firebug or to return / alert it upon the fnDraw() request so that I can the entire array that I am loading? I am generating the results above by calling the AJAX request directly by the address.

    Thank you for your attention, sir.

    Shameless
  • allanallan Posts: 63,407Questions: 1Answers: 10,452 Site admin
    Got it - sEcho is 1 in both cases. You need to echo back the value of sEcho that DataTables gives to you for each case. This is just a counter at the moment. Also worth noting that it's worth casting this as an integer on the server for security.

    Firebug should show you the XHR go out and come back in, and that will show you the string that is returned from the server. An alternative would be to console.dir() in fnServerData.

    Regards,
    Allan
  • shamelessshameless Posts: 31Questions: 0Answers: 0
    edited March 2010
    *******************************
    SOLVED--tia
    *******************************

    Alan,

    I think I "get it" conceptually, but obviously I am making a mistake. I am using http://datatables.net/usage/server-side as my example

    [code]
    oTable.push($('#'+sid).dataTable( {
    "bPaginate": false,
    "bLengthChange": false,
    "bJQueryUI": true,
    "bServerSide": true,
    "bProcessing": true,
    "bAutoWidth": false,
    "asStripClasses": [ 'alt1', 'alt2' ],
    /* AJAX SOURCE */ "sAjaxSource": sAJx,
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    },
    "aoColumns": [
    /* id */ { "bVisible": false },
    /* icon */ { "fnRender": function ( oObj ) {
    var shtml= oObj.aData[0];
    if(isNumber(shtml)){
    var sspan = "";
    return sspan;
    }
    } },
    /* Quantity*/null,
    /* Origin Date*/null,
    /* Filled Date*/null,
    /* Bid*/null,
    /* Partial*/null,
    /* Trans*/{ "bVisible": false },
    /* InZIP*/null,
    /* Expires*/null
    ]
    } ));
    [/code]

    Q: Do I need to set "sSource" in the line "url": sSource," to a value or is it's value inherited from "sAjaxSource" in the preceding parameter?

    Q: Does "aoData" have to be set in "data": aoData, " ? If it is not set, should this line be present? Same for ""success": fnCallback"?

    Lastly, I am trying to retrieve and return the value of sEcho via this PHP:

    [code]
    $outerJSON .= '{';
    $outerJSON .= '"sEcho": '.$_POST["sEcho"].',';
    $outerJSON .= '"iTotalRecords": '.count($results).',';
    $outerJSON .= '"iTotalDisplayRecords": '.count($results).',';
    [/code]

    The response in Firebug is:

    A PHP Error was encountered

    Severity: Notice
    Message: Undefined index: sEcho

    The relevant POST value was:

    sEcho 1


    I get the feeling that I am messing up the initialization, but all my experiments are yielding approximately the same results. Sorry to be a bother.

    Shameless
  • allanallan Posts: 63,407Questions: 1Answers: 10,452 Site admin
    Hi Shameless,

    I see you've got a 'solved' note in your post - are you happy with how this works now? Or any outstanding questions still?

    Allan
This discussion has been closed.