fnReloadAjax - Count rows before & after
fnReloadAjax - Count rows before & after
I'm trying to tell if an ajax request has pulled new rows, and refresh the page if it has.
[code]
// AJAX this and get results to repopulate table every 10 seconds
setInterval(function() {
// Get the old length
var oTable = $('.dataTable').dataTable();
oldLength = oTable.fnGetData().length;
console.log('Old: '+oldLength);
// AJAX it
oTable.fnReloadAjax();
// Get the new length
oTable = $('.dataTable').dataTable();
newLength = oTable.fnGetData().length;
console.log('New: '+newLength);
// If any changes have been made, reload page
if(oldLength != newLength)
{
//document.location.reload();
console.log('CHANGED');
}
}, 10000);
[/code]
The two console.logs's ALWAYS show the same number. Why aren't they getting the length correctly?
[code]
// AJAX this and get results to repopulate table every 10 seconds
setInterval(function() {
// Get the old length
var oTable = $('.dataTable').dataTable();
oldLength = oTable.fnGetData().length;
console.log('Old: '+oldLength);
// AJAX it
oTable.fnReloadAjax();
// Get the new length
oTable = $('.dataTable').dataTable();
newLength = oTable.fnGetData().length;
console.log('New: '+newLength);
// If any changes have been made, reload page
if(oldLength != newLength)
{
//document.location.reload();
console.log('CHANGED');
}
}, 10000);
[/code]
The two console.logs's ALWAYS show the same number. Why aren't they getting the length correctly?
This discussion has been closed.
Replies
[code]
// AJAX this and get results to repopulate table every 10 seconds
setInterval(function() {
// Get the old length
var oTable = $('.dataTable').dataTable();
oldLength = oTable.fnGetData().length;
console.log('Old: '+oldLength);
// AJAX it
oTable.fnReloadAjax( null, function () {
// Get the new length
oTable = $('.dataTable').dataTable();
newLength = oTable.fnGetData().length;
console.log('New: '+newLength);
// If any changes have been made, reload page
if(oldLength != newLength)
{
//document.location.reload();
console.log('CHANGED');
}
} );
}, 10000);
[/code]
Allan