我正在使用CodeIgniter,数据表和JQuery验证。我必须在ajax成功函数中使用数据表以在视图上显示记录。记录没有问题。全部显示而没有数据表。现在我必须在ajax成功中使用数据表。我不知道应该在哪里使用数据表。
您能帮助我如何在Ajax成功使用数据表吗?
jQuery验证
$("form[name='set_reports']").validate({
rules: {
report_type:{required:true}
},
submitHandler: function(form) {
var report_type = $('#report_type').val();
var fromDate = $('#fromDate').val();
var toDate = $('#toDate').val();
$.ajax({
url: baseUrl + "/Reports_control/Get_reports",
method: "POST",
data: {report_type: report_type,fromDate:fromDate,toDate:toDate},
success: function(response) {
var data = JSON.parse(response);
if (data.status === 'error')
{
alert(data.msg);
}
if (data.status === 'success') {
$('.report_list').show();
var trHTML = '';
$.each(data.records, function (i, o){
trHTML += '<tr><td>'+o.Sr_no+
'</td><td>' + o.cutomer_name +
'</td><td>'+ o.o_order_no +
'</td><td>'+ o.created_by +
'</td><td>'+ o.o_date_of_added +
'</td></tr>';
});
$('.search_record tbody').append(trHTML);
}
}
});
}
});
获取报告功能
if (empty($getOutput) || $getOutput == 0){
$arr_result['status'] = "error";
$arr_result['msg'] = "No record found";
}
else
{
$n=1;
foreach ($getOutput as $row)
{
$results[] = array(
"Sr_no" => $n,
"cutomer_name" => $row->c_firstname.' '.$row->c_lastname,
"o_order_no"=>$row->o_order_no,
"created_by" =>$row->firstname.' '.$row->lastname,
"o_date_of_added"=>$row->o_date_of_added
);
$n++;
}
$arr_result['status'] = 'success';
$arr_result['records'] = $results;
}
echo json_encode($arr_result);
查看
<table cellspacing="0" id="datatable_list">
<thead>
<tr>
<th>Sr. No.</th>
<th>Cutomer name</th>
<th>Product</th>
<th>Product Qty </th>
<th>Order No</th>
<th>Created By</th>
<th>Date of Create</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
$(document).ready( function () {
$('#datatable_list').DataTable();
} );
</script>
我尝试了此代码,但现在问题是搜索无法正常工作。有人可以帮助我解决此问题吗?