Issue with fnReloadAjax

Issue with fnReloadAjax

MorriganMorrigan Posts: 10Questions: 0Answers: 0
edited September 2009 in Bug reports
Hi,

I tried using the fnReloadAjax() plugin function as shown in the API, and it actually works... but there is something I really don't understand. When I watch the console with Firebug in Firefox, I see that whenever I fire the event that calls fnReloadAjax (it's on an onchange event of a dropdown located outside of the table), the ajax URL is called... three times! Any idea how this can be?

Here's my setup: I have a list of album reviews in a data table, which works fine. Outside of it, I have a dropdown menu with a bunch of review rating ranges, with onchange='dataTable.fnReloadAjax("http://localhost/review/ajax-list-browse/by/rating/selection/" + this.value)'.

When I fire the onchange, I see ALL of these URLs being called (I cleared the console before firing the event of course), displayed in this order in Firebug:

http://localhost/review/ajax-list-browse/by/rating/selection/60?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=30&iSortingCols=1&iSortCol_0=4&iSortDir_0=desc

http://localhost/review/ajax-list-browse/by/rating/selection/60

http://localhost/review/ajax-list-browse/by/rating/selection/60?sEcho=3&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=30&iSortingCols=1&iSortCol_0=4&iSortDir_0=desc

I have used the fnReloadAjax() as-is from the API. The list gets refreshed just as expected, but the multiple server calls worry me, and also baffle me. I have added the following line inside the fnReloadAjax() definition:

console.log(sNewSource);

And in the console I see my URL as passed from the onchange event ONLY, so obviously the other ajax calls are deeper inside jquery, but I haven't figured it out.

Any ideas?

Thanks.

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Hi Morrigan,

    I'm not a gambling person, but I'd be willing to put money on the fact that you are using server-side processing - is that right? If you are, then remember that every table draw will go to the server to get information from the server-side processing script for what should be displayed. So in fact there is no need to reload the Ajax source, you just need to call fnDraw() to reload the current page :-)

    Regards,
    Allan
  • MorriganMorrigan Posts: 10Questions: 0Answers: 0
    edited September 2009
    But I don't want to reload the current data table: I want to dynamically feed a new ajax URL into the data table whenever I change the dropdown value. That's the point of the fnReloadAjax function, isn't it?
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Hi Morrigan,

    Ah I see - so you just want to change the address from where DataTables is sending it's Ajax requests for the information to draw? That's done by altering the sAjaxSource property, rather like what the fnReloadAjax() plug-in does (which really isn't suitable for use when using server-side processing!). How about something like:

    [code]
    oTable.fnSettings().sAjaxSource = sNewSource;
    oTable.fnDraw();
    [/code]

    Regards,
    Allan
  • MorriganMorrigan Posts: 10Questions: 0Answers: 0
    Ah, yes, that's what I needed then. Thanks!
  • kookaburrakookaburra Posts: 1Questions: 0Answers: 0
    oTable.fnSettings().sAjaxSource = sNewSource;
    oTable.fnDraw();

    This is not working for me.
    All i have to do is just destroy the previous table and re-initialize it. It's working fine though, but i'd also like to make it work like the above.
This discussion has been closed.