I am trying date range search using jquery ajax and show data in datatable.
Here is my php controller code.
public function date()
{
$date_from = date('Y-m-d H:i:s', strtotime($this->input->post('date_from')));
$date_to = date('Y-m-d H:i:s', strtotime($this->input->post('date_to')));
if ($date_from != "" && $date_to != "") {
$data[] = $this->report_model->get_report_by_date($date_from, $date_to);
$output= $data;
}
echo json_encode($output);
}
Here is my Javascript code
$('#filterDate').click(function () {
var from_date = $('#from_date').val();
var to_date = $('#to_date').val();
if (from_date != '' && to_date != '') {
$.ajax({
url: "<?php echo base_url(); ?>report/date",
method: "POST",
data: {date_from: from_date, date_to: to_date},
dataType: "json",
success: function (output) {
$("#reportDataOld").remove();
var json = $.parseJSON(output);
alert(json.html);
if (output == "err") {
alert("Something Happened Wrong! Please Try Again.");
} else {
$("#reportDataNew").html(output);
console.log(output);
}
}
})
;
}
else {
alert("Please Select Date");
}
});
I get json response like this
But Cant represent data in Datatable.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…