JQuery的数据表 - AJAX重装如何当返回没有赶上 [英] JQuery DataTables - AJAX reloading how to catch when nothing is returned

查看:192
本文介绍了JQuery的数据表 - AJAX重装如何当返回没有赶上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是数据表中,并允许记录从数据库中删除。删除后,我重新加载该表显示最近的变化。不过,如果我从数据库中删除最后一个记录,由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;
    }

这篇关于JQuery的数据表 - AJAX重装如何当返回没有赶上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆