ajax refresh

ajax refresh

capeckcapeck Posts: 54Questions: 13Answers: 1
edited February 2010 in General
Hi,
I'm getting confused on how to best go about refreshing my data table. I want to refresh my table based on a radio button change. On that change event, I want to do something like this:
$.ajax({
type: "POST",
url: "get_maps.php",
data: dataString,
dataType: "json",
success: function(data){
/* Example call to load a new file */
oDataTable.fnReloadAjax( 'get_maps.php' );
}
});
It seems the $.ajax is already getting the new data, so what do I send fnReloadAjax? Or should I be looping through the JSON response on success and doing a fnAddData? I do need to do a post as the data loaded in my PHP needs a parameter. Thanks in advance for any help.

Replies

  • klbnklbn Posts: 4Questions: 0Answers: 0
    edited February 2010
    have the same problem actually , what is the solution for this?

    i have tried ,

    [code]
    success: function(data){

    oTable.fnClearTable(0);
    oTable.fnAddData(data);
    oTable.fnDraw();
    }
    [/code]
    data is a json string and in the api it says its possible to add multiple rows with fnAddData. yet when i do thati it says columns do not match , and its the same query working... Is there way to make a Ajax Load with post parameters? if so can someone give an example or some pointers?

    EDIT:

    i have tried ,

    [code] "fnServerData" : function(sSource, aoData, fnCallback){
    $.ajax({
    "dataType" : 'json',
    "type" : "POST",
    "url" : sSource,
    "data" : aoData,
    "success" : fnCallback
    });
    [/code]

    I guess this will do what i want to do , yet i cant call fnServerData from an event...

    Kind regards
  • capeckcapeck Posts: 54Questions: 13Answers: 1
    Thanks for the quick response. This helps, but what I want is to refresh the table (doing an ajax POST to get the data) from an outside event, in my case a change in a radio button.
  • zernikzernik Posts: 2Questions: 0Answers: 0
    I have the same problem. Any of the API functions have no impact on the existing table.
    In general, there are two questions here.
    1. Is there a way to pass arguments to the ajax when I do fnDraw?
    2. If there isn't a way to impact the server, does it mean that I need to erase the current dataTable and start from scratch?
    3. What's the API to erase a dataTable?
    4. Why when my ajax comes back from any API command it is not taken by the dataTable. (the "processing" icon keeps going)

    Thanks,
    Uri
    650 330-0651
  • klbnklbn Posts: 4Questions: 0Answers: 0
    well i have come up with a temp solution giving a json.txt file as a fnReloadAjax source
  • klbnklbn Posts: 4Questions: 0Answers: 0
    @capeck
    [code]
    $.ajax({
    type: "POST",
    url: "get_maps.php",
    data: dataString,
    dataType: "json",
    success: function(data){
    /* Example call to load a new file */
    oDataTable.fnReloadAjax( 'get_maps.php' );
    }
    });
    [/code]

    there's a simple solution for that yet it took me a day to figure that out.

    the data is coming in json format , just do

    [code]

    success: function(data){
    /* Example call to load a new file */
    oDataTable.clearTable();
    oDataTable.fnAddData(data.aaData); //the data part of your json message
    oDataTable.fnDraw();
    }
    [/code]

    i hope this will do the trick ... yet i couldn't manage to do it with server side processing
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You can use fnServerData - http://datatables.net/usage/callbacks#fnServerData . Here is an example showing it's use with server-side processing (will work with Ajax sourced data as well): http://datatables.net/examples/server_side/post.html

    Regards,
    Allan
This discussion has been closed.