Dynamic Datatable not displaying any data into row after ajax json success

Dynamic Datatable not displaying any data into row after ajax json success

ashishaware28ashishaware28 Posts: 1Questions: 1Answers: 0

Code:
View:

Student Attendance
Employee Name Day
function expensedynamintable(){ var expense_type =$('#expense_type').val(); console.log(expense_type); var from_date = $('#from_date').val(); console.log("from Date",from_date); var to_date = $('#to_date').val(); console.log("To Date",to_date); var t =$("#example1").DataTable(); var i = 1; t .clear() .draw(); $.ajax({ url : "<?php echo site_url('expenses/expensefilterctrl'); ?>/",//+stud_course_id, data: {'expense_type' : expense_type, 'from_date': from_date, 'to_date': to_date}, type: "POST", dataType: "JSON", success: function(data) { $.each(data,function(key,val) { //val.course_id, //val.stud_id t.row.add( [ i++, // "manager_firstname", val.expense_type, val.expense_amount ] ).draw( false ); //i++; } ); }, error: function (jqXHR, textStatus, errorThrown) { alert('Error get data from ajax'); } });//ajax cld //}); // Automatically add a first row of data // $('#addRow').click(); $('#example2').DataTable({ "paging": true, "lengthChange": true, "searching": true, "ordering": true, "info": true, "autoWidth": true });//example 2 cld //}//);//stud_course_id cld }//);//function cld

Json Result :
[{"expense_id":"9","expense_type":"FPL","expense_amount":"245.00","expense_date":"2016-05-26","expense_mode"
:"Others"},{"expense_id":"10","expense_type":"FPL","expense_amount":"21.00","expense_date":"2016-05-27"
,"expense_mode":"Others"}]

Json give perfect result. Still Datatable not displaying any data into raw. It show only search bar and navigation

This discussion has been closed.