I have written one function that makes one ajax call and gets the data and creates a table.I calling this function again and again.But while doing that I am getting reinitialization of table error.Can someone please help me to fix the issue.
Function :
function getLibraryFilesStudent() {
var reqBody = {
"uploader": Cookies.get('user')
};
$.ajax({
url: '../library/libraryfilegetlist',
data: JSON.stringify(reqBody),
dataType: 'json',
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
error: function(data) {
console.log(data);
},
success: function(data) {
if (data.length) {
var trHTML = [];
for (var i = 0; i < data.length; i++) {
var test = '<input type="radio" class="radio" name="selectFile" value=' + data[i].id + "," + data[i].keyword + ",flag=1" + '>';
trArr = [data[i].name, data[i].keyword, test]
trHTML.push(trArr);
if (data.length == trHTML.length) {
$('#lFileList').DataTable({
data: trHTML,
bSort: false,
pageLength: 4,
columns: [{
title: "Name"
},
{
title: "keyword"
},
{
title: "Action"
}
]
});
}
}
}
},
type: 'POST'
});
}