jquery - 如何在 laravel 中提交表单后重新加载数据表?
问题描述
你好我正在用laravel构建一个项目,我将多个数据从CategoryController传递到Category刀片文件,但问题是当我插入数据时它已成功插入,我想用新记录重新加载数据表但我现有的id 为 example1 的表正在进入另一个 id 为 example1 的表中,为什么?这是我的代码...
脚本
$("#example1").DataTable();
$(document).on('submit','.database_operation',function(e){
e.preventDefault();
var url = $(this).attr('action');
var data = $(this).serialize();
$.ajax({
url:url,
method:"POST",
data:data,
success:function(fb){
var resp = $.parseJSON(fb);
// console.log(resp);
if(resp.status=='true'){
toastr.success(resp.message,'Success');
$('#myModal').hide();
$('.modal-backdrop').remove()
$(document.body).removeClass("modal-open");
$('#example1').DataTable().clear().destroy();
$("#example1").DataTable();
$("#example1").load(" #example1");
}else if(resp.status=='false'){
$.each( resp.message, function( key , value ) {
toastr.error(value + '<br>','Error');
});
}else if(resp.status=='false-1'){
toastr.error(resp.message,'Error');
}
}
});
return false;
});
嘿,我是 laravel 和 jquery 的初学者,正在尝试学习,请以最好的方式帮助我。
解决方案
尝试添加 $('#example1').DataTable().ajax.reload(); 在响应状态为真之后。
在此处阅读实际问题
推荐阅读
- reactjs - 更改分页选择/活动项目背景颜色
- javascript - 为什么我的函数不在 ajax 中发送变量?
- c# - iOS、Swift、Xamarin 中的生命周期感知
- javascript - 如何在 iOS 上的 PWA 中删除“无网络”警报
- python - 我在解析 XML 文件时遇到的一个案例
- chapel - 函数返回一个关联数组
- java - Java中双重检查锁定的问题
- java - 在 Android 应用程序中使用 Google 登录后如何获取 Google 帐户联系人?
- rust - 这个 Rust 匹配表达式可以简化吗?
- rust - 我如何为只接受 &self 的自定义记录器提供内部状态?