Dinamic file ajax

Dinamic file ajax

ftatarliftatarli Posts: 4Questions: 0Answers: 0
edited May 2011 in General
It is possible i make a function to return the name of the file that dataTable will read ? Because this works fine:

[code]

$(document).ready(function () {
$('#example').dataTable({
"sAjaxSource": 'json_source.txt'
});
});

[/code]

But i need a function to set the name of the file. I try this but doesn't work.

[code]

$(document).ready(function () {
$('#example').dataTable({
"sAjaxSource": function test(){return 'json_source.txt';}
});
});

[/code]

I'm starting so I don't know if it is possible or silly.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    It's a good idea - but I'm afraid that won't work with the stock DataTables since it expects sAjaxSource to be a string. Can't you just assign the string that is returned from the function, or do you need it to run at a later time? For example

    [code]

    function test(){return 'json_source.txt';}

    $(document).ready(function () {
    $('#example').dataTable({
    "sAjaxSource": test()
    });
    });

    [/code]
    Allan
  • ftatarliftatarli Posts: 4Questions: 0Answers: 0
    Thanks this works fine.
This discussion has been closed.