问题描述
当我在删除 ajax 中添加函数 fetchcategory();
时,我的表没有刷新:
$(document).on('click','.delete_category_btn',function (e) {
e.preventDefault();
var cat_id = $('#delete_cat_id').val();
alert('Category Deleted!');
// location.reload();
$('#deleteCategoryModal').modal('hide');
fetchcategory();
//token taken from laravel documentation
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "DELETE",url: "/clinical/bbr-category-configuration-delete/"+cat_id,dataType: "dataType",});
});
另一个参考是我这里的 add 函数在添加新表后重新加载页面:
$.ajax({
type: "POST",url: "/clinical/bbr-category-configuration",data: category_data,dataType: "json",success: function (response){
console.log(response);
if(response.status == 400) {
$('#category_formCheck').html("");
$('#category_formCheck').addClass('alert alert-danger');
$.each(response.errors,function (key,err_values) {
$('#category_formCheck').append('<li>'+err_values+'</li>');
});
}
else
{
$('#category_notif').html("");
$('#category_notif').addClass('alert alert-success');
$('#category_notif').text(response.message);
$('#createCategory').modal('hide');
fetchcategory();
}
}
});
$.ajax({
type: "DELETE",
但它们没有出现,所以我把它们放在 on(click
为什么我的删除 ajax 没有刷新我的表?
更新:
解决方法
你可以在ajax成功中做到这一点。我相信 fetchcategory()
方法正在将数据填充到表中
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).on('click','.delete_category_btn',function (e) {
e.preventDefault();
var cat_id = $('#delete_cat_id').val();
// location.reload();
$('#deleteCategoryModal').modal('hide');
$.ajax({
type: "DELETE",url: "/clinical/bbr-category-configuration-delete/"+cat_id,dataType: "dataType",success: function(data) {
alert('Category Deleted!');
fetchcategory();
},error: function() {
alert('Error occured');
}
});
});
</script>