JQuery的数据表 - AJAX重装如何当返回没有赶上重装、数据表、JQuery、AJAX

2023-09-11 01:14:08 作者:绝境边缘

我使用的是数据表中,并允许记录从数据库中删除。删除后,我重新加载该表显示最近的变化。不过,如果我从数据库中删除最后一个记录,由AJAX调用返回null,并且不更新数据表(它仍显示刚删除的记录)。

I am using a datatable and allow records to be deleted from the database. After deletion, I reload the table to display the recent changes. However, if I delete the last record from the database, null is returned by the AJAX call and does not update the datatable (it still displays the record that was just deleted).

我的呼叫删除功能后执行:

My Call after the delete function is performed:

oTable.fnDraw();
oTable.fnReloadAjax();

这里的控制台错误是:

The console error here is:

json.aaData is null
[Break On This Error] for ( var i=0 ; i<json.aaData.length ; i++ ) 

有没有一种方法来检测时,没有从AJAX返回,这样的数据表中可以检测到没有记录并显示数据表空的消息(如表无数据)?

Is there a way to detect when nothing is returned from AJAX so that the datatable can detect that there are no records and display the 'datatable empty' message (i.e. No data available in table)?

推荐答案

确定这样的问题是在服务器端,当我的SQL查询是空的它返回NULL作为aaData ['aaData']值。

Ok so the issue was on the server side, when my sql queries were empty it was returning NULL as the aaData['aaData'] value.

刚刚加入这个,现在它返回一个表就是一句:

Just added this and now it returns as a table that is just empty:

if(mysql_num_rows($result)==0){
        $aaData = array();
        $aaData['aaData']='';
        echo json_encode($aaData);
        exit;
    }