我的故事板:
我有一个使用php从mysql查看数据的表。 每行都有一个按钮,可以将一行预览到模态引导程序中。
现在,我可以将一个字段(可能是单元格)传递给url吗? 在我的情况下,no_request将是一个参数。 因为这一个字段将是一个参数
这是我的观点:
<table>
<tbody>
<?php
$no = 1;
foreach($data_request as $data) {
?>
<tr>
<td class="center"><?php echo $no++.". ";?> </td>
<td class="sorting1" id='no_request'><?php echo $data['code_office'].'/'.$data['code_departement'].'/'.date ('m', strtotime($data['month'])).'/'.$data['id_request'];?> </td>
<td class="center"><?php echo "$name"; ?></td>
<td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['waktu_mulai']));?></td>
<td class="center"><?php echo $data['complaint'];?></td>
<td class="center"><span class="label label-warning"><?php echo $data['status_request'];?></span></td>
<td class="center"><?php echo date ("d-m-Y, H:i ",strtotime($data['closing_request']));?></td>
<td class="center">
<a class="btn btn-danger" href="#">
<i class="halflings-icon white trash"></i> Close
</a>
<a class="btn btn-success" href="#" id="print" req_id="<?php echo $data['id_request']; ?>">
<i class="halflings-icon pencil"></i> Print
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="modal hide fade" id="myModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1>Print Preview</h1>
</div>
<div class="modal-body">
<p id="id_preview"> </p>
</div>
<div class="modal-footer">
// This is the problem
<a href="<?php echo base_url().'control_closing/generate_pdf/no_request ?>" class="btn btn-primary">Create PDF</a>
<a href="#" class="btn" data-dismiss="modal">Close</a>
</div>
</div>
<script>
$('.btn-success').click(function(e){
e.preventDefault();
var $this = $(this);
var $trData = $this.closest('tr').clone();
$trData.find('td:last').remove();
var $thData = $this.closest('table').find('thead').clone();
$thData.find('th:last').remove();
var $table = $('<table border="2"></table>');
$table.append($thData).append($trData);
$("#id_preview").html($table);
$('#myModal').modal('show');
});
function passing_id_to_url{
//How to passing no_request to url ?
}
</script>
答案 0 :(得分:0)
由于您使用的是Jquery,并且我假设您要将数据发回URL,您可以使用隐藏的表单:
<form id="pdf<?php echo $no++;?>">
<input type="hidden" name="office" value="<?php echo $data['code_office'];?>" />
<input type="hidden" name="complaint" value="<?php echo $data['complaint'];?>" />
....
<a class="btn btn-success" onclick="submit(<?php echo $no;?>)>Create PDF</a>
</form>
然后使用Ajax发布表单数据
function submit(id) {
$.ajax({
url:'/control_closing/generate_pdf/no_request',
type:'post'
data:$('form#pdf'+id).serialize(),
success:function(html) {
modal(html);
}
});
}
function modal() {
//.... Code for modal
}