hello guys im new in codeigniter and using AJAX。 所以我要問一個簡單的問題如何從模型中獲取參數到AJAX中查看
我想在阿賈克斯從參數解析數據轉換成模型
因此,當我打開網頁的數據表是從查詢表我做模型
這是我的代碼片段:
THE VIEW
<?php
//echo form_open('redo/edit_simpan');
//echo form_open('person/insert_detail');
foreach ($data->result() as $v) {
$id = $v->id_request;
$unit = $v->unit_permintaan;
$dokumen = $v->nomor_dokumen_pendukung;
$tanggal = $v->tanggal;
$status = $v->status;
}
>
$(document).ready(function() {
//datatables
table = $('#table').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo site_url('barang/ajax_list/')?>/",
"type": "POST"
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
}); }
控制器
public function ajax_list()
{
$list = $this->barang->get_datatables();
$data = array();
$no = $_POST['start'];
foreach ($list as $person) {
$no++;
$row = array();
$row[] = $person->nama_barang;
$row[] = $person->jumlah_barang;
$row[] = $person->satuan_barang;
$row[] = $person->keterangan_barang;
//add html for action
$row[] = '<a class="btn btn-sm btn-primary" href="javascript:void(0)" title="Edit" onclick="edit_person('."'".$person->id_request."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm btn-danger" href="javascript:void(0)" title="Hapus" onclick="delete_person('."'".$person->id_request."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>
<a class="btn btn-sm btn-success" href="edit_data/'.$person->id_request.'" title="Add_Detail" ><i class="glyphicon glyphicon-plus"></i> Barang</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->barang->count_all(),
"recordsFiltered" => $this->barang->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
模型
function get_datatables($idreq)
{
$this->_get_datatables_query();
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$this->db->where('id_request',$idreq); //paramter
$query = $this->db->get();
return $query->result();
}
我想參數$ idreq到顯示爲 查看任何線索的數據表怎麼樣?
我想是$沒有= $ V數據 - > $ id_request入get_datatables模型($ idreq)
從哪裏'$ idreq'的值在您的模型中傳遞? –
感謝Hek mat,從視圖中,在頂部,在變量上$ no我想從$ no解析數據到我的模型($ idreq) – Ppad
它是否與'$ _POST ['start''];?相同。我的意思是$ idreq和$ _POST ['start']的值是相同還是不同? –