I'm using ajax to call a partial view with a table inside a div called "div-GVPrevision". I'm using datatables, but I'm getting an error after the ajax call, and it says:
"DataTables warning: table id=GVPrevision - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3"
This is the ajax code:
<script>
function GVPrevision() {
$('#GVPrevision').DataTable({
"aaSorting": [],
aLengthMenu: [
[4, -1],
[4, "Todo"]
],
responsive: false
});
}
$(document).ready(function () {
GVPrevision();
$('.btnagregar').click(function (event) {
event.preventDefault();
var data = {
"codmov": $("#codmovf").val(),
"fechainicio": $("#fechainiciof").val(),
"fechatermino": $("#fechaterminof").val(),
"rutentidad": $("#rutentidadf").val(),
"motivo": $("#motivof").val()
};
$.ajax({
url: "/Ficha/AgregarfooterPrevision",
type: "POST",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json",
success: function (response) {
if (response.Success) {
$("#div-GVPrevision").load('@Url.Content("~/Ficha/GVPrevision")');
GVPrevision();
}
else
window.location.href = "@Url.Action("Prevision", "Ficha")";
},
error: function () {
console.log('Login Fail!!!');
}
});
});
});
</script>