I need that when I click on the <a> tag, I am redirected to the desired page and the data I want is loaded in a data table. This is the code in js:
function listBodega(){
$.ajax({
type: "POST",
url: window.location.pathname,
data: {
action:'devices_bodega'
},
success:function(data){
$(function () {
tblCierre = $('#bodega').DataTable({
scrollX: true,
// responsive: true,
autoWidth: false,
destroy: true,
deferRender: true,
sAjaxDataProp: "",
ajax: {
url: window.location.pathname,
type: 'POST',
data: {
'action': 'devices_bodega'
},
dataType: 'json',
},
columns: [
{"data": "serial"},
{"data": "mac"},
{"data": "nombre_modelo"},
{"data": "nombre_marca"},
{"data": "login"},
{"data": "recibido"},
{"data": "Tipo"},
{"data": "EnviadorPor"},
],
initComplete: function (settings, json) {
}
});
});
},
error: function(){
alert(textStatus+': ' +errorThrown);
},
});
}
The href is good , but the function listBodega() is not working. So, how can I make that ajax work? Because the function's ajax doesn't work and it jumps to the error directly.
in HTML:
<a onclick = "listBodega()" href="{% url 'apli:bodega_list' %}" class="nav-link">