javascript - 如何在响应ajax jquery后创建数据表
问题描述
我有一个问题,我想在用 ajax jquery 发送数据后在这里调用数据表,在这里我很难,因为我将创建的数据表是服务器端的,因为服务器端调用脚本是成功的并且如果 console.log (response) 它将根据数据表的格式输出数据,如下所示
draw: null
recordsFiltered: 9
recordsTotal: 9
data:(9) [{..}] (and other)
这是我发送数据的代码
var urlajax = "<?= $this->url->get($this->router->getControllerName() . '/ajaxbynip')?>";
$("#btn-filter").click(function(){
var data = $('#form-filter').serialize();
$.ajax({
url:urlajax,
type:"get",
data:data,
success:function(response){
console.log(response);
//how can i create datatables server-side in here?
}
});
});
我尝试使用此代码,但它不起作用
tabel = $('#ats-dt-basic-datatbles').DataTable({
stateSave: true,
"processing": true,
"serverSide": true,
"ordering": true,
"order": [[ 0, 'asc' ]],
"iDisplayLength": 50,
"ajax":
{
"url": urlajax,
"type": "POST"
},
"deferRender": true,
"aLengthMenu": [[5, 10, 50],[ 5, 10, 50]],
"columns": [
{ "data": "no" },
{ "data": "name" },
{ "data": "PERAN" },
{ "data": "action" },
],
});
解决方案
$("#btn-filter").click(function(){
var data = $('#form-filter').serialize();
$.ajax({
url:urlajax,
type:"get",
data:data,
success:function(response){
console.log(response);
//you can try this one --> call a function or url with ajax
// ==>url can be a php file like createDB.php or any function url
// write code in specific url or php file that call from ajax url for create a database according to your passing data
$.ajax({
url: url,
type:"POST",
data:response,
success:function(response){
console.log(response);
}
});
}
});
});
推荐阅读
- python - 如何使用 Django OMR 查询集更新表的 las 行?
- windows - 如何以当前登录的 Windows 用户身份从 Go 向 AD 进行身份验证?
- python - 按包含来自列表的子字符串的字段过滤 sqlalchemy 查询
- java - 如何使用 Swing 制作单个可调整大小的列?
- python - 如何对 Pandas 列中的每个唯一值进行排序和计数
- javascript - 如何将每 N 次第一个 N 元素从一个数组推送到另一个数组?
- node.js - 我可以在没有私钥的情况下连接到 ssh2 吗?
- docker - MQTT 与 NGINX 和 Let's Encrypt
- xml - 解释一下这个 xs:simpleContent / xs:extension XSD 模式?
- c++ - c ++不一致的无符号到有符号减法结果仅对一种排列失败