ajax.reload () DOES NOT work

0

I am working on a project for the institute but I can not make it through ajax the DataTable is reloaded after inserting the record in the DB and in the console this error is generated:

Uncaught TypeError: Cannot read property 'ajax' of undefined
at Object.success (categoria.js:106) //esta es la linea en la cual llamo a ajax.reload()
at i (jquery3.min.js:2)
at Object.fireWith [as resolveWith] (jquery3.min.js:2)
at A (jquery3.min.js:4)
at XMLHttpRequest.<anonymous> (jquery3.min.js:4)

The Code that I have is the following:

function list(){

$table= $("#tblistado").dataTable(
{
    "languaje": {
        "url":"cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json" 
//tampoco funciona el lenguaje 
//aunque de menor importancia para el proyecto

    },
    "aProcessing": true, //Activamos el procesamiento de datatables
    "aServerSide": true, //Paginacion y filtrados Realizados por el Servidor
    dom : 'Bfrtip', // Definimos los elementos del control de la tabla
    buttons:[
                'copy',
                'excel',
                'csv',
                'pdf'
            ],
    "ajax":         // se llama la Url AL CASE LISTAR POR METODO $_GET desde categoria.php
            {
                url: '../../ajax/categoria.php?operacion=list',
                type:"get",
                dataType:"json",
                error: function(e){ console.log(e.responseText);}

            },
    "bBdestroy": true,
    "iDisplayLenght": 5, //paginacion, es decir, cada cuanto elementos
    "order": [[0,"desc"]] //ordenar (columna, orden)

}).DataTable();
}

// Save or edit function

function saveAndEdit(e){

e.preventDefault();// No se activara la accion predeterminada del evento
$("#btnGuardar").prop("disabled",true);
var formData = new FormData($("#formulario")[0]);

jQuery.ajax({
        url:"../../ajax/categoria.php?operacion=saveandedit",
        type:"POST",
        data:formData,
        contentType: false,
        processData: false,

    success: function (datos){
        alert(datos);
        showForm(false);
        table.ajax.reload(); // linea 106 del error de la consola

    }
});

}

-I've made sure that Jquery is the first to be loaded and the footer -I tried to put $ .ajax instead of jQuery.ajax -I tried to use table.api (). ajax.reload () -I tried to change from dataTable to DataTable according to the documentation Nothing has worked.

In addition to this but less important

    
asked by Alvaro Santafe 22.09.2017 в 03:15
source

1 answer

1
  

Uncaught TypeError: Can not read property 'ajax' of undefined

table is defined within the function list() , so it does not exist within saveAndEdit(e)

You can access it:

success: function (datos){
    var table = $('#tblistado').DataTable(); // accede de nuevo a la DataTable.
    alert(datos);
    showForm(false);
    table.ajax.reload(); // linea 106 del error de la consola
}
    
answered by 22.09.2017 / 07:30
source