3

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++ ) 

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)?

3 Answers 3

1

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;
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Put your JSON data in a wrapper, and have the wrapper tell you there's no data, instead of returning null:

{"data":[... your current data ...],"total":0,"success":true}

Comments

0

I suspect you need to look at your server side code and find why aaData is null. I use datatables and when there are no records the json generated is:

...,"aaData":[],...

and empty message displays fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.