How to refresh the row of a table when it is updated by Ajax?

0

I have the following Jquery script with ajax

$('#btn_cofr_update').click(function(e){
    e.preventDefault();
    var form =$('#form_upd_requi');
    var action=form.attr('action');
    var id=$('#id_').val();

     var data=$('#form_upd_requi').serialize();
     var url=$(this).attr('href');

     $.ajax({
       type:'PUT',
       url:'/admin/requirements/'+id,
       data:data,
       success:function(data){
         console.log(data);
       },
       error:function(data){
         console.log('mal');
       }
     });
     
  });

It works fine, but in order to update the view I have to reload the page I would like to know how I can do it so that I can update the table without recharging the whole page Muchas Graciass

    
asked by Fercho Jerez 14.02.2017 в 18:27
source

3 answers

1

use tuTabla.ajax.reload (); once you have received ajax modification response.

I leave the documentation: link

    
answered by 31.05.2017 в 20:15
0

$('#btn_cofr_update').click(function(e){
    e.preventDefault();
    var form =$('#form_upd_requi');
    var action=form.attr('action');
    var id=$('#id_').val();

     var data=$('#form_upd_requi').serialize();
     var url=$(this).attr('href');

     $.ajax({
       type:'PUT',
       url:'/admin/requirements/'+id,
       data:data,
       success:function(data){
         $("#form_upd_requi").load(location.href+" #form_upd_requi>*","");
       },
       error:function(data){
         console.log('mal');
       }
     });
     
  });
    
answered by 14.02.2017 в 19:10
0

To be able to do what you need, I can suggest the following:

  • Your ajax function should receive a confirmation that the values were modified in your database.
  • Once the confirmation is received, you must update the columns (1,2,3 ... n), in the row corresponding to your ID, with the values that you sent to the AJAX function.
  • You can also replace the content of the TR element, with the html that the server responds to. Example response to replace the content of serious TR: "Value 1, Row 10Value 2, Row 10Value 3, Row 10"
  • I have prepared an example on the following link link

        
    answered by 14.02.2017 в 21:20