reload table with ajax.url().load not working

reload table with ajax.url().load not working

coderman1coderman1 Posts: 6Questions: 1Answers: 0
edited August 2014 in Free community support
function status_changed()
    {
        var value = document.getElementById("campaign_status").value;
        var table = $('#example').DataTable();
        var url = "../json/json.get_campaigns.php?filter=" + value;
        table.ajax.url(url).load();
    }


 $(document).ready(function()
    {
        var table = $('#example').DataTable( {
            "fnServerData": function ( sSource, aoData, fnCallback ) {
                $.ajax( {
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": fnCallback
                } );
            },
            "sAjaxSource": "../json/json.get_campaigns.php?filter=Active",
...}

What I am basically trying to do is update the contents of a table based on the selected value in a combo box. I am trying to get it to reissue the json call with the new supplied url, but I can see in the chrome debugger that ajax.url(url) is not actually requesting the new URL, it is requesting the one thats defined in sAjaxSource.

Am I doing this the right way?

Answers

  • larsonatorlarsonator Posts: 54Questions: 4Answers: 2
    edited August 2014

    you could do it like this

    ajax: {
        "url": /json/json.get_campaigns.php
        "data": function( d ) {
            d.id=$("select.selection option:selected").val();
        }
    },
    

    and then call the reload function every time the selection is changed.
    Datatables will fun the 'Data' function each time and get the new value.

  • allanallan Posts: 61,433Questions: 1Answers: 10,049 Site admin

    I'd suggest doing it the way @larsonator says. having said that, your own method should work, and if you could link to a test case showing the issue I'll debug what is going wrong.

    Allan

This discussion has been closed.