[英]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 这是我的Ajax脚本
$('.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();
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.