Problems with Div when reloading jquery

1

My problem is simple, the solution is not for me.

I have an operation in my JS which I do:

$(document).ready(function () {
$('.botonEliminar').click(function (e) {

   e.preventDefault();

   var fila = $(this).parents('tr');
   var id = fila.data('id');

   var form = $('#form-delete');

   var url = form.attr('action').replace(':user_id', id);

   var data = form.serialize();

   $.post(url,data, function (respuesta) {
       //alert(respuesta);
       //fila.fadeOut();



       location.reload();

   }). fail(function () {
       alert('No se pudo eliminar el usuario');
   });  }); });

Anyway, what I want is that I do not do the location.reload (); Therefore, what I need is for the div that I do the validation to refresh without doing the whole page.

$("#container").load("/");

In that what I do is refresh the DIV but at the same time I insert the home page which I just want to refresh that DIV.

What do you advise me?

Use: Laravel 5.3 Jquery 2.1.3

Anyway, the Laravel works well for me, the problem is the DIV and my execution.

    
asked by Her Asd 02.11.2016 в 16:28
source

2 answers

1

Only remove the reload line; if you need to show some information in the div.

$(document).ready(function () {
$('.botonEliminar').click(function (e) {

   e.preventDefault();

   var fila = $(this).parents('tr');
   var id = fila.data('id');

   var form = $('#form-delete');

   var url = form.attr('action').replace(':user_id', id);

   var data = form.serialize();

   $.post(url,data, function (respuesta) {
       //alert(respuesta);
       //fila.fadeOut();

$("#container").html('<h2>Guardado con éxito</h2>');

   }). fail(function () {
       alert('No se pudo eliminar el usuario');
   });  }); });

If what you want to show is the data, which is returned by the insert, then that data should come in the response variable, preferably in json

    
answered by 02.11.2016 / 17:10
source
1
$(document).ready(function () {
$('.botonEliminar').click(function (e) {
  //bloqueas el boton y evitas hacer submits mientras esta procesando
  $('.botonEliminar').prop('disabled', true);

  e.preventDefault();
  var fila = $(this).parents('tr');
  var id = fila.data('id');
  var form = $('#form-delete');
  var url = form.attr('action').replace(':user_id', id);
  var data = form.serialize();

  $.post(url,data, function (respuesta) {
   // si la respuesta es el texto que quieres mostrar, 
   // si es json o cualquier cosa pues respuesta.mensaje... 
   // Lo que tengas, eso depende de tu tipo de respuesta
   $('#div_respuesta').html(respuesta); 

   // si quieres añadir y no cargarte lo que tiene ese div, 
   // o el elemento que sea, no tiene por que ser div.
   // o bien si recorres un array y quieres mostrar toda la info 
   // de ese array en un div
   $('#div_respuesta_append').append(respuesta);


  }). fail(function () {
    $('#div_respuesta').html("no se pudo modificar el usuario"); 
    // me ahorro un alert
  }).always(function() {
    // vuelvo a poner el boton activo, ya sea success o fail
    $('.botonEliminar').prop('disabled', false);
  });
}); 
});

Try to see

    
answered by 02.11.2016 в 17:54