简体   繁体   中英

Ajax perform update and delete page won't auto refresh i'm using laravel 5.5

whenever i update or delete item from my table it wont automatically refresh the table, i need to reload the page every-time i perform those two function[edit and delete]

here is my Ajax Script

 $('.modal-footer').on('click', '.edit', function() {

    $.ajax({
        type: 'post',
        url: '/setup/batch/edit',
        data: {
            '_token': $('input[name=_token]').val(),
            'id': $("#fid").val(),
            'batch_name': $('#n').val()
        },
        success: function(data) {
            $('.item' + data.id).replaceWith("<tr class='item" + data.id + "'><td>" + data.batch_name + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-name='" + data.batch_name + "'><span class='glyphicon glyphicon-edit'></span> Edit</button> <button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-name='" + data.batch_name + "' ><span class='glyphicon glyphicon-trash'></span> Delete</button></td></tr>");
        }
    });
});//Delete// $('.modal-footer').on('click', '.delete', function() {
    $.ajax({
        type: 'post',
        url: '/setup/batch/delete',
        data: {
            '_token': $('input[name=_token]').val(),
            'id': $('.did').text()
        },
        success: function(data) {
            $('.item' + $('.did').text()).remove();
        }
    });
});

if you want to reload page after the process has been done you can do the following

$('.modal-footer').on('click', '.edit', function() {

$.ajax({
    type: 'post',
    url: '/setup/batch/edit',
    data: {
        '_token': $('input[name=_token]').val(),
        'id': $("#fid").val(),
        'batch_name': $('#n').val()
    },
    success: function(data) {
      location.reload();
    }
});
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM