Delete records that I have in the bbdd

0
function cargaPagina(pagina)
    {
      var desde = pagina * itemsPorPagina;
      $.ajax({
        data:{"param1":"dame","limit":itemsPorPagina,"offset":desde},
        type:"GET",
        dataType:"json",
        url:"Conexion_Contacto.php"
      }).done(function(data,textStatus,jqXHR){

        var lista = data.lista;

        $("#miTabla").html("");

        $.each(lista, function(ind, elem){


          $("<tr>"+
            "<td >"+elem.id_contacto_empresa+"</td>"+
            "<td>"+elem.nombre_contacto_empresa+"</td>"+
            "<td>"+elem.telefono_contacto_empresa+"</td>"+
            "<td>"+elem.correo_contacto_empresa+"</td>"+
            "<td>"+elem.razon_social_empresa+"</td>"+

            "<td>"+'<button data-toggle="modal" data-target="#modalEdicion" class="btn btn-primary modalEdicion">Editar</button> '+"</td>"+
            "<td>"+'<button class="btn btn-danger remove-item">Eliminar</button>'+"</td>"+


            "</tr>").appendTo($("#miTabla"));

        });     


      }).fail(function(jqXHR,textStatus,textError){
        alert("Error al realizar la peticion dame".textError);

      });

       /* Remove Item */
      $("body").on("click",".remove-item",function(){

        confirm('Eliminar Datos', '¿Esta seguro de eliminar este registro?');
        var id = $(this).parent("td").data('idpersona');
        var c_obj = $(this).parents("tr");

        $.ajax({
          dataType: 'json',
          type:'POST',
          url: url + 'eliminar_contacto_empresa.php',
          data:{id:id}
        }).done(function(data){
          c_obj.remove();
          toastr.success('Item Deleted Successfully.', 'Success Alert', {timeOut: 5000});
          getPageData();
        });

      });
    
asked by Keane 13.09.2017 в 04:50
source

1 answer

1

Hello: At first glance you see two things that are not clear ...

1) The url variable in the remove_item function (as @jotaelesalinas points) seems to be undefined.

2) In the remove_item function you have this code:

var id = $(this).parent("td").data('idpersona');

but, in the function page_charging it seems to be undefined:

  "<td>"+'<button class="btn btn-danger remove-item">Eliminar</button>'+"</td>"+

I think I should say:

'<td idpersona="' + elem.id_contacto_empresa + '">'+'<button class...

I recommend you always look at the browser's debugger by checking which variables are actually sent to the server.

Atte, Pablo.

    
answered by 13.09.2017 / 16:39
source