Как разбивать мои строки результата ajax в codeigniter. Я хочу отобразить мой результат ajax, который будет составлять 10-20 строк в партии по 4 или 5 строк на странице. Продвинь меня. Это не Ajax pagination, но это ajax, разбивающийся по страницам в ajax-вызове. СпасибоСтроки результата Ajax - как рисовать?
Это мой вид файла:
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.12/datatables.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> </script>
<script>
$(document).ready(function(){
$("#getreport").click(function(){
var fromdate = $('#date1').val();
var todate = $('#date2').val();
$("#header").css("visibility", "visible");
// $("#bodycontent").empty();
// $("#bodycontent").html('<div id="subcontent"></div>');
data =
{
"from" : fromdate,
"to" : todate
}
$.post('<?=site_url("Report/managecustomers_report"); ?>', data ,function (data) {
$('#datatable').dataTable({
data : data
// columns : [
// { 'data' : 'picture'},
// { 'data' : 'customername'},
// { 'data' : 'contactperson'},
// { 'data' : 'mobilenumber'},
// { 'data' : 'phone'},
// { 'data' : 'email'},
// ]
});
});
});
});
</script>
<div class="table-responsive">
<table class="table allcp-form theme-warning fs13">
<thead>
<tr class="bg-light">
<th class="">Image</th>
<th class="">Customer Name</th>
<th class="">Contact Person</th>
<th class="">Mobile Number</th>
<th class="">Phone</th>
<th class="">Email</th>
</tr>
</thead>
</table>
</div>
Мой контроллер:
public function managecustomers_report()
{
$query = $this->Reportmodel->customerreport_select($this->input->post('from'),$this->input->post('to'));
$data = $query['records'];
$this->output->set_content_type('application/json');
$this->output->set_output(json_encode($data));
return $data;
}
Моя модель файла:
public function customerreport_select($date1,$date2)
{
$this->db->where('date >=', $date1);
$this->db->where('date <=', $date2);
$query=$this->db->get('customers');
$row = $query->result();
print_r($row);
return array(
'records' => $row,
'count' => count($row));
}
вы должны отступ кода ... – onzinsky
Это не хорошая практика, но вы можете создать HTML в самом контроллере, а затем вернуть этот HTML в вашем AJAX запрос. А затем замените html с помощью jQuery. – kishor10d