[英]How to pass request Id value to modal?
When I click on 'edit' button modal is open but in a hidden field no I can't receive RequestId. 当我单击“编辑”按钮时,模态已打开,但是在隐藏字段中,否,我无法接收RequestId。 Please help me how to pass dynamic requested to modal form?
请帮我如何通过动态请求到模态形式?
This I will use in Codeigniter framework. 我将在Codeigniter框架中使用它。
If it is possible to please rewrite the code I will be most helpful. 如果可以的话,请重写代码,我将非常有帮助。
<table width="100%" class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col" align="left">#</th>
<th scope="col">Request Id</th>
<th scope="col">Agent Id</th>
<th scope="col">Type</th>
<th scope="col">Value</th>
<th scope="col">Comment</th>
<th scope="col"> Request Date & Time</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$sn=1;
foreach ($result as $row) {
//print_r($row);die();
?>
<tr>
<td align="left"><?php echo $sn ?></td>
<td><?php echo $row['rid'];?></td>
<td><?php echo $row['aid'];?></td>
<td><?php echo $row['type'];?></td>
<td><?php echo $row['value'];?></td>
<td><?php echo $row['comment'];?></td>
<td><?php echo $row['request_time'];?></td>
<td><button class="btn btn-danger btn-sm">Open</button></td>
<td>
<a data-toggle="modal" href="<?php base_url()?>#myModal" class="btn btn-warning btn-sm">Edit</a>
</td>
</tr>
<?php $sn++;}?>
</tbody>
</table>
You could add 您可以添加
data-request-id="<?php echo $row['rid']?>"
to the buttons that open the modals, and than use jquery/javascript to fetch the data with ajax 到打开模态的按钮,然后使用jquery / javascript用ajax获取数据
var requestId = $('.modalBtn').attr("data-request-id");
The is a sample to pass the ID to modal by using HTML data-attributes & jQuery. 是使用HTML数据属性和jQuery将ID传递给模式的示例。
<table width="100%" class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col" align="left">#</th>
<th scope="col">Request Id</th>
<th scope="col">Agent Id</th>
<th scope="col">Type</th>
<th scope="col">Value</th>
<th scope="col">Comment</th>
<th scope="col"> Request Date & Time</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$sn=1;
foreach ($result as $row) {
//print_r($row);die();
?>
<tr>
<td align="left"><?php echo $sn ?></td>
<td><?php echo $row['rid'];?></td>
<td><?php echo $row['aid'];?></td>
<td><?php echo $row['type'];?></td>
<td><?php echo $row['value'];?></td>
<td><?php echo $row['comment'];?></td>
<td><?php echo $row['request_time'];?></td>
<td><button class="btn btn-danger btn-sm">Open</button></td>
<td>
<a href="#myModal" data-toggle="modal" data-id="<?php echo $row['rid'];?>" class="btn btn-warning btn-sm">Edit</a>
</td>
</tr>
<?php
$sn++;
}?>
</tbody>
</table>
<script>
$('#myModal').on('show.bs.modal', function (e) {
var $btn = e.relatedTarget,
rId = $btn.data('id');
// "rId" would be the value from the html data-attribute.
console.log(rId);
});
</script>
<table width="100%" class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col" align="left">#</th>
<th scope="col">Request Id</th>
<th scope="col">Agent Id</th>
<th scope="col">Type</th>
<th scope="col">Value</th>
<th scope="col">Comment</th>
<th scope="col"> Request Date & Time</th>
<th scope="col">Status</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php
$sn=1;
foreach ($result as $row) {
//print_r($row);die();
?>
<tr>
<td align="left"><?php echo $sn ?></td>
<td><?php echo $row['rid'];?></td>
<td><?php echo $row['aid'];?></td>
<td><?php echo $row['type'];?></td>
<td><?php echo $row['value'];?></td>
<td><?php echo $row['comment'];?></td>
<td><?php echo $row['request_time'];?></td>
<td><button class="btn btn-danger btn-sm">Open</button></td>
<td>
<a onclick="load_item('<?php echo $row['rid'];?>');" class="btn btn-warning btn-sm">Edit</a>
</td>
</tr>
<?php $sn++;}?>
</tbody>
</table>
Javascript Code You had to insert 您必须插入的Javascript代码
function load_item(rid){
/**
Write your ajax/javascript code here
*/
$("#myModal").modal("show");
}
Remove data-toggle="modal"
from <a>
tag and make onclick
edit based on ID 从
<a>
标记中删除data-toggle="modal"
并根据ID进行onclick
编辑
<td>
<a id="edit-form" href="#" class="btn btn-warning btn-sm">Edit</a>
</td>
JS JS
$('#edit-form').click(function() {
$('#hidden_field_id').val(your-value);
$('#myModal').modal('show');
});
If I am right, you wanted to display a modal after clicks on the edit button. 如果我说得对,您想在单击编辑按钮后显示一个模式。
<a href="javascript:void(0)" onclick="get_modal_details('<?php echo $row['rid'];?>')" class="btn btn-warning btn-sm">Edit</a>
I hope $row['rid']
is your unique ID and here is a html modal code 我希望
$row['rid']
是您的唯一ID,这是html模式代码
<div class="modal" id="detail_modal_pop" style="overflow: scroll;"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header" > <button type="button" class="close close_c_modal" >×</button> <h4 class="modal-title c_modal">Details</h4> </div> <div class="modal-body"> <h6 id="load_wait" class="text-center">Please wait...</h6> <div id="detail_modal_pop_result" style="display:none;"></div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default close_c_modal" >Close</button> </div> </div> </div> </div>
To display a modal on clicks on edit button, use below script 要在点击“编辑”按钮时显示模式,请使用以下脚本
<script> function get_modal_details(rid) { $('#detail_modal_pop').fadeIn(200); $("#detail_modal_pop_result").hide(); $("#load_wait").show(); jQuery.ajax({ url: "<?php echo base_url() ?>some_controller/controller_method", data: { rid: rid }, type: "POST", success:function(data){ $("#load_wait").hide(); $("#detail_modal_pop_result").show(); $("#detail_modal_pop_result").html(data); }, error:function (){} }); } $(".close_c_modal").on("click", function() { $('#detail_modal_pop').fadeOut(200); $("#detail_modal_pop_result").hide(300); $('#detail_modal_pop_result').html(''); $("#load_wait").show(300); }); </script>
And here is the PHP code 这是PHP代码
<?php //"Some_controller.php" Controller public function controller_method() { if(isset($_POST['rid'])) { $rid = (int)$_POST['rid']; // $get_info = $this->Model->get_info($rid); // Write modal content here... } } ?>
Hope this will help you. 希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.