空ajax响应的数据表错误(Datatable error for empty ajax response)

编程入门 行业动态 更新时间:2024-10-28 12:30:34
空ajax响应的数据表错误(Datatable error for empty ajax response)

我在我的项目中使用了Datatable 1.9.2。 我通过AJAX显示申请人名单。 还有一个过滤器表单,用于过滤数据。 一切工作正常,但问题是,如果我筛选记录和数据库没有返回数据然后datatable在POPUP中生成一个错误。 有人可以指导我如何处理与数据表空ajax响应,如何处理空数据集。 以下是我正在使用的代码

$('#applicants_list').dataTable( { "bProcessing": true, "bServerSide": true, "sPaginationType": "bootstrap", "sDom": '<"H"Cfr>t<"F"ip>', "oColVis": { "activate": "mouseover", "aiExclude": [ 10 ], "sAlign": "left" }, "bFilter": false, "sAjaxSource": script.php, "aoColumns": [ {"bSortable": true }, // attachments {"bSortable": true }, //Subject Line {"bSortable": true }, // Date Sent {"bSortable": true }, // File Name {"bSortable": false }, {"bSortable": false }, {"bSortable": true }, {"bSortable": true }, {"bSortable": true }, {"bSortable": false } ], "aaSorting": [[0, 'desc']] } );

i am using Datatable 1.9.2 in my project. I am display a list of applicants in it via AJAX. There is also a filter form which is used to filter data. Everything is working fine, but the problem is that if i filter records and no data is returned by DB then datatable generates an error in POPUP. Can someone guide me how to handle empty ajax response with datatable, how to handle empty dataset. Below is the code which i am using

$('#applicants_list').dataTable( { "bProcessing": true, "bServerSide": true, "sPaginationType": "bootstrap", "sDom": '<"H"Cfr>t<"F"ip>', "oColVis": { "activate": "mouseover", "aiExclude": [ 10 ], "sAlign": "left" }, "bFilter": false, "sAjaxSource": script.php, "aoColumns": [ {"bSortable": true }, // attachments {"bSortable": true }, //Subject Line {"bSortable": true }, // Date Sent {"bSortable": true }, // File Name {"bSortable": false }, {"bSortable": false }, {"bSortable": true }, {"bSortable": true }, {"bSortable": true }, {"bSortable": false } ], "aaSorting": [[0, 'desc']] } );

最满意答案

当过滤器返回记录为空时,只返回来自server / ajax响应的以下数据,它将显示空记录消息。

echo '{ "sEcho": 1, "iTotalRecords": "0", "iTotalDisplayRecords": "0", "aaData": [] }';

Just return following data from server/ajax response when filter return record is empty it will display empty record message.

echo '{ "sEcho": 1, "iTotalRecords": "0", "iTotalDisplayRecords": "0", "aaData": [] }';

更多推荐

本文发布于:2023-07-29 20:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据表   错误   ajax   Datatable   response

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!