php - 插入数据后是否可以在不插入codeigniter的情况下立即显示表格行?
问题描述
插入数据后是否可以在不插入 codeigniter 的情况下立即显示表格行?我不想使用套接字,但我也找不到解决方案,因为当我使用 ajax 时,div 会自我复制。
解决方案
您可以通过使用 ajax 来做到这一点。
我们在这里需要 2 个 ajax 调用。1. 用于填充数据。2.用于插入数据。
成功插入数据后,您可以启动 List 功能。下面给出了一个代码示例。
function populateList(){
var resultHtml = '';
$.ajax({
type: "POST",
dataType: "json",
url: 'api/for/getting/list/of/data',
data:{},
cache: false,
success:function(response) {
$.each(response.list,function(key,val){
resultHtml += '<tr>';
resultHtml += val.name;
resultHtml += '</tr>';
resultHtml += '<tr>';
resultHtml += val.mobile;
resultHtml += '</tr>';
resultHtml += '<tr>';
resultHtml += val.address;
resultHtml += '</tr>';
})
//Populate in in the <tbody> of the table
$('#list_table').html(resultHtml);
}
});
}
$('#insert_buttom').click(function(){
$.ajax({
type: "POST",
dataType: "json",
url: 'api/for/inserting/data',
data:{},// pass all the data here
cache: false,
success:function(response) {
populateList();
}
});
})
推荐阅读
- c# - Unity中如何减少List.Contain()引起的GC
- amazon-web-services - 代码管道在 github 的源阶段失败
- php - 警告:include_once(D:\XAMPP\htdocs\_includes itle.php)
- laravel - 将 Laravel 从 5.7 升级到 5.8 后出现“classblade.compiler 不存在”
- css - `overflow-block` 和 `overflow`(和 `block-overflow`)有什么区别?
- python - 正则表达式在python中查找部分匹配的特殊字符
- javascript - AntiForgeryToken 不在同一解决方案的子项目中验证
- performance - 检查哪个物体与相机视锥体碰撞
- html - 如何在循环中包含 mixins 并在 pug 中获取数据
- apache-kafka - 流式传输是否适用于事务数据用例?