How to get value from server side

How to get value from server side

gent59gent59 Posts: 10Questions: 0Answers: 0
edited June 2011 in General
Hello there,

I'm searching to get value from server side with my data.php and put it in a .

my data.php:
[code]
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"test"=> $something,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
[/code]

i want to display the value of "test" (which is also the value of $something) in my

maybe i can use $.GetJSON or something else?
Can somebody give me any idea,

Thanks,
gent

Replies

  • gent59gent59 Posts: 10Questions: 0Answers: 0
    there is nobody to help me, neither Allan????
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    As noted here - http://datatables.net/forums/comments.php?DiscussionID=5012 - I try to, but simply can't respond to all posts due to the volume of them... :-)

    There is an example showing how what you want can be done with fnServerData here: http://datatables.net/release-datatables/examples/server_side/custom_vars.html .

    Allan
  • gent59gent59 Posts: 10Questions: 0Answers: 0
    thanks Allan for your help, but it's not exactly what I'm looking for, in fact I'm looking to obtain iTotalRecords's value and display it anywhere.

    Regards,
    Gent
  • gent59gent59 Posts: 10Questions: 0Answers: 0
    ... To be more clear, I noticed that to know iTotalRecords's value or iTotalDisplayRecords's value , i have to call: function _fnAjaxUpdateDraw ( oSettings, json ), and for iTotalRecords's value or iTotalDisplayRecords's value we just do, json.iTotalRecords etc...
    my question is how can i call this function from another js file, like:
    [code]

    // here I call get iTotalRecords's value by calling _fnAjaxUpdateDraw ( oSettings, json ), how can i do it???

    /* Initialise datatables */
    var oTable = $('#example').dataTable({

    "bServerSide": true,
    "bProcessing": true,
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "sAjaxSource": "data.php",
    });


    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited June 2011
    The answer is in the link I posted before :-). Where it says:

    [code]
    /* Do whatever additional processing you want on the callback, then tell DataTables */
    [/code]
    That's where you want to do your thing. For example

    [code]
    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "scripts/server_processing.php",
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push( { "name": "more_data", "value": "my_value" } );
    $.getJSON( sSource, aoData, function (json) {
    alert( json.iTotalRecords );
    fnCallback(json)
    } );
    }
    } );
    } );
    [/code]
    Allan
  • gent59gent59 Posts: 10Questions: 0Answers: 0
    Yes, it works , thank you very much Allan, keep working well as you are doing,

    thanks again,

    Gent
  • gent59gent59 Posts: 10Questions: 0Answers: 0
    It is possible to alert( // value of json.iTotalRecords //); outside of $('#example').dataTable ?
    (I tried with API's functions but without success )

    thanks,
    Gent
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You can just store it in a variable if you want or pass it into a function.

    Allan
  • gent59gent59 Posts: 10Questions: 0Answers: 0
    I see Allan, thanks, for people who don't know how to process, i did like this:
    [code]
    $.getJSON( sSource, aoData, function (json) {
    alert( json.iTotalRecords );
    _your_function(json.iTotalRecords);
    fnCallback(json)
    } );
    .
    .
    .

    function _your_function(a){
    alert(a); // display value you've sanded, in this case it's json.iTotalRecords's value
    }
    [/code]

    regards
    gent
  • gent59gent59 Posts: 10Questions: 0Answers: 0
    Allan, if I want to put a function into $.getJSON( sSource, aoData, function (json) { function my_function(){ return json.iTotalRecords;}}); how can I call from an other js file or my_function, the example I did above is not very useful, for example if I use a slider ui It's a real problem...! (store in a variable is a good idea, but I failed :-( )

    thanks,
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You could just have a global variable could you not? Or an object method or object property or whatever.

    function(json) {
    my_global = json.iTotalRecords;
    fnCallback(json)
    }

    Allan
This discussion has been closed.