How do I re-initialize DataTables. The ajax function loads the data from books.xml every 10 seconds.
How do I re-initialize DataTables. The ajax function loads the data from books.xml every 10 seconds.
The DataTable complains than I cannot re-draw DataTables.
Function to make ajax call every 10 Seconds.
function func1(){
$.ajax({
type: "GET",
url: "books.xml",
dataType: "xml",
async : false,
success: function(xml) {
$(xml).find('book').each(function(){
var Col0 = $(this).find('author').text();
var Col1 = $(this).find('title').text();
var Col2 = $(this).find('genre').text();
$('#test').append('<tr><td>'+Col0+'</td><td>'+Col1+'</td><td>'+Col2+'</td></tr>');
});
}
});
};
$(document).ready(function(){
func1();
});
setInterval(func2,10000);
function func2(){
$("#test").html("");
func1();
}
HTML Data:
Author | Title | Genre |
---|---|---|
Author | Title | Genre |
Answers
I would very much suggest you use the
clear()
androws.add()
API methods to refresh the data. Orajax.reload()
if you are usingajax
.You could use
destroy()
but that is a very inefficient way of doing it.Allan