auto ajax reload issues
auto ajax reload issues
lothar83fr
Posts: 7Questions: 0Answers: 0
hello allan
at first sorry for my english because i'm french...
i want to reload my table automatically every seconds so i use this one:
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback )
{
if ( typeof sNewSource != 'undefined' )
{
oSettings.sAjaxSource = sNewSource;
}
this.fnClearTable( this );
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
$.getJSON( oSettings.sAjaxSource, null, function(json) {
// Got the data - add it to the table
for ( var i=0 ; i
at first sorry for my english because i'm french...
i want to reload my table automatically every seconds so i use this one:
[code]
$.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback )
{
if ( typeof sNewSource != 'undefined' )
{
oSettings.sAjaxSource = sNewSource;
}
this.fnClearTable( this );
this.oApi._fnProcessingDisplay( oSettings, true );
var that = this;
$.getJSON( oSettings.sAjaxSource, null, function(json) {
// Got the data - add it to the table
for ( var i=0 ; i
This discussion has been closed.
Replies
Given that there are two url's being used and the formatting of the first one - I'd very much say that you are using server-side processing. Is this correct?
In which case, you don't need to use fnReloadAjax() at all, because each draw will update the displayed information from the server! As such you can just call fnDraw() and the redraw will occur with whatever data the server sends back.
Regards,
Allan
now, i have this:
[code]
function AutoReload(){
oTable.fnDraw();
//on rappel cette fonction ind
Interesting that this causes your browser to freeze after a while. When DataTables redraws the table with server-side processing, it completely destroys all of the old data in the table, so I wonder if there might be a DOM memory leak somewhere (do you attach events to the table at all?). If you could post a link to an example showing this issue, it might be able to profile the memory use and figure out why this might be happening!
Thanks,
Allan
Indeed the function call by "fnDrawCallback" is the origin of this issue, but I don't know why.
If i remove this function, i quote a big improvement.
fnOpenDetails() code:
[code]
function fnOpenDetails ( oSettings )
{
tableeee = $("td", oTable.fnGetNodes() ).each( function () {
$(this).click( function () {
//on fait apparaitre le block d
Thanks very much for the links and code - makes life much easier :-).
I'd say that the problem is the "click" event handler in the fnOpenDetails() function. What I think the problem is, is that when you add this event, it means that the rows cannot be deleted by the Javascript engine's garbage collector (since it is still "in use" - as far as it can tell) - hence the slow down in the long run.
Therefore, my suggested fix would be to remove the 'click' event just before the table is redrawn (possibly the easiest way of doing this is using a custom server-side 'get' function since this will run every time the table is redrawn, doing an Ajax get for you - http://datatables.net/usage/server-side#fnServerData ). See http://docs.jquery.com/Events/unbind for removing event handlers.
Sound reasonable?
Allan
Can you please tell me how did you get arround the problem, I can see the CPU spike everytime I do a refresh....
I have the same click event and add the event on call Back....
Thanks
Sobers
This is my conf:
[code]
"fnDrawCallback": function() {
$('#tbl_lst_ejection tbody tr').each( function () {
$(this).click(fnOpenDetails);
} );
},
"fnServerData": function ( sSource, aoData ,fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": function (oSettings) {
$('#tbl_lst_ejection tbody tr').each( function () {
$(this).unbind('click',fnOpenDetails);
} );
fnCallback(oSettings);
}
} );
[/code]
I have always the problem but less important. If i do lots of refresh (more than 2000) firefox freezing and that without event click or other extras.
Jean-philippe
I still have the same problem... I donot refresh the page as much, but do it every 5 secs
I still see the spike and after sometime the browser freezes.... Navigating to another page takes some time, coz possible memory leak...
Alan/, can you please tell us the sequnce of calling stack and what functions need to be used,
I am using oTable.fnDraw();, which is helpful over fnReloadAjax, since it makes 2 calls and second one w/o params...
Anyone has a solution, please post ... Thanks in Advance