【发布时间】:2019-10-09 07:49:33
【问题描述】:
我想使用表单方法将数据发布到细节控制器,它需要前一个视图中的一些数据。
这是我的看法:
<form role="form" action="<?php echo URL_CTR;?>general/do_performance/detail" method="post">
<div role="tabpanel" class="tab-pane fade in active" id="per_provinsi">
<h3 style="margin: 30px 0px 0px 0px;" class="text-center" id="title_do_1">Performance by <?php echo lang('gen.province.text');?></h3>
<table class="table mb0 table-striped" id="table_1" class="table_width">
<thead>
<tr>
<th style="width: 1%;"><?php echo lang('gen.no.text');?></th>
<th>Plant</th>
<th><?php echo lang('gen.province.text');?></th>
<th style="width: 10%;">Total DO</th>
<th style="width: 10%;">DO tidak terlambat</th>
<th style="width: 15%;">Lead Time Performance</th>
<th style="width: 5%;"><?php echo lang('gen.option.text');?></th>
</tr>
</thead>
<tbody id="data_1">
</tbody>
</table><br>
</div>
</form
这是我的脚本:
function load_data_1(data) {
var html = "";
for (var i = 0; i < data.length; i++) {
var a = '<tr>\
<th>' + (i + 1) + '</th>\
<td>' + data[i].gudang_nama + '<br>( ' + data[i].gudang_no_referensi + ')</td>\
<td>' + data[i].provinsi_nama + '<br>( ' + data[i].provinsi_id + ')</td>\
<td>' + data[i].total_data + '</td>\
<td>' + data[i].tepat_waktu + '</td>\
<td>' + data[i].delivery_rate + '</td>\
//this is the data i wanted to send
<input type="hidden" name="plant_id" value="'+data[i].gudang_id+'">\
<input type="hidden" name="param_id" value="'+data[i].provinsi_id+'">\
<input type="hidden" name="code" value="1">\
<td>\
<button class="btn btn-success dropdown-toggle btn-xs" type="submit" title="<?php echo lang('gen.detail.text');?>"><?php echo lang('gen.detail.text');?></button>\
</td>\
</tr>';
html = html + a;
}
$("#table_1").dataTable().fnDestroy();
$('#data_1').html(html);
$('#table_1').dataTable({
// "scrollX": true,
});
}
我想将数据传递给这个控制器:
public function detail() {
$data = array();
$data["plant_id"]= $this->input->post('plant_id');
$data["code"]= $this->input->post('code');
$data["param_id"]= $this->input->post('param_id');
echo json_encode($data);
}
但结果显示了for数据的最后一个(plant_id 104和param_id 891是循环的最后一个数据):
{
plant_id: "104", //this is the last data in looping for
code: "1",
param_id: "891", //this is the last data in looping for
}
在循环'for'中,单击同一行按钮时如何只发送数据?
【问题讨论】:
标签: javascript php html loops codeigniter