How to get datatables to show new information sent to the database?
How to get datatables to show new information sent to the database?
dt_user
Posts: 51Questions: 16Answers: 0
ERROR1: DataTables warning: table id=task_table - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
ERROR2: Uncaught TypeError: Cannot set property 'data' of null.
function updateRecord(){
//var dt = $("#task_table").DataTable();
var start = $('#std').val();
console.log(start);
var end = $('#etd').val();
console.log(end);
var projname = $('#projname').val();
console.log(projname);
var task_name = $('#taskname').val();
console.log(task_name);
var details = $('#details').val();
console.log(details);
var lvl = $('#lvl').val();
console.log(lvl);
var statuss = $('#status').val();
console.log(statuss);
var comments = $('#comments').val();
console.log(comments);
var edit_id = $('#edit_id').val();
console.log("edit_id="+edit_id);
// var dt = $('#task_table').DataTable({
// 'ajax': {
// "type": "POST",
// "url": "/controller/update-sheet.php",
// "data": function( d ) {
// d.start = $('#std').val();
// d.end = $('#etd').val();
// d.projname = $('#projname').val();
// d.task_name = $('#taskname').val();
// d.details = $('#details').val();
// d.lvl = $('#lvl').val();
// d.statuss = $('#status').val();
// d.comments = $('#comments').val();
// d.edit_id = $('#edit_id').val();
// },
// "dataSrc": "",
// "dataType": "json",
// },
// "columns": [
// {data: "StartTD"},
// {data: "EndTD"},
// {data: "CMDProjects"},
// {data: "TaskName"},
// {data: "Status"},
// {data: "HoursWorked"},
// {data: 'Comments'},
// {data: 'Details'},
// {data: 'Level of Difficulty'},
// {data: 'Total Hours Worked'}
// ]
// });
// dt.ajax.reload();
$.ajax({
url:"update-sheet.php",
type:"POST",
data:{
'start':start,
'end':end,
'proj':projname,
'taskname':task_name,
'details':details,
'lvl':lvl,
'status':statuss,
'comments':comments,
'edit_id':edit_id,
},
dataType: "json",
success:function(response){
console.log(response);
//var response = JSON.parse(data);
console.log(response);
if (response['success'] == true){
$('.messages').html(response['messages']).fadeOut();
//reset the form
$('#createSheet').fadeOut();
//reload datatables
setInterval( function (){
dt.ajax.reload(null, false );
}, 30000 );
//table.ajax.reload();
} else{
$('.messages').html(response['messages']);
//reload datatables
$("#task_table").DataTable().ajax.reload(null, false);
//$('#createSheet').modal('hide');
}
}//success()
});//ajax()
}
This discussion has been closed.
Answers
For the Invalid JSON Error please start by following the troubleshooting steps at the link provided in the error:
http://datatables.net/tn/1
Hard to say without seeing it happen by looking at your page or a test case replicating the issue. My guess is the Ajax data structure doesn't match your table. What is the script doing when this happens?
Kevin
Well ajax is giving me parent and child row data. I thought I could edit both at the same time.
From my research I found out that you can only use ajax.reload if you are using datatables ajax option. Otherwise use draw() to refresh datatables.
Yep, that's correct. Kevin explained more on your other thread.