我想從這個模態中獲取 id 并將它傳遞到另一個頁面,比如 edit_appointment.php?id='id from modal' 問題是我將我的 php 代碼執行到不同的檔案,只是使用 Ajax 請求將我的資料顯示到模態。我不知道如何在這里呼叫用戶 ID a href="" >Edit Appointment
這是我的代碼
<div class="modal fade" id="AppointmentDetails">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 id="modalTitle" class="modal-title">Appointment Details</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div id="modalBody" class="modal-body">
<div class="viewdetails">
</div>
</div>
<div class="modal-footer">
<a href="" class="btn btn-secondary" data-dismiss="modal">Close</a>
<a href="" class="btn btn-info userdata">Edit Appointment</a>
</div>
</div>
</div>
</div>
if(isset($_POST['userid']))
{
$id = $_POST['userid'];
$sql = "SELECT a.*, CONCAT(p.fname,' ',p.lname) AS pname,p.phone,p.email,d.name AS dname FROM tblappointment as a JOIN tblpatient as p ON p.id = a.patient_id JOIN tbldoctor as d ON d.id = a.doc_id WHERE a.id = '$id' ";
$query_run = mysqli_query($conn,$sql);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $row)
{
?>
<table class="table table-borderless table-responsive table-sm">
<thead>
<tr>
<th style="width: 40px"></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th class="text-muted">Client:</th>
<td><a href=""><?php echo $row['pname'];?></a></br>
<?php echo $row['phone'];?></br>
<?php echo $row['email'];?></td>
</tr>
<tr>
<th class="text-muted">Doctor:</th>
<td><?php echo $row['dname'];?></td>
</tr>
<tr>
<th class="text-muted">Date:</th>
<td><?php echo date('F, j Y',strtotime($row['schedule'])); ?></td>
</tr>
<tr>
<th class="text-muted">Time:</th>
<td><?php echo date('h:i A',strtotime($row['starttime'])).' - '.date('h:i A',strtotime($row['endtime'])); ?></td>
</tr>
<tr>
<th class="text-muted">Reason:</th>
<td><?php echo $row['reason']; ?></td>
</tr>
<tr>
<th class="text-muted">Status:</th>
<td>
<?php
if($row['status'] == 'Confirmed')
{
echo $row['status'] = '<span class="badge badge-success">Confirmed</span>';
}
?>
</td>
</tr>
</tbody>
</table>
<?php
}
}
else{
echo $return = "<h5> No Record Found</h5>";
}
}
我使用 Ajax Request 從模態獲取資料
eventClick: function(info) {
var userid = info.event.id;
$.ajax({
type: "post",
url: "calendar_action.php",
data: {userid:userid},
success: function (response) {
$('.viewdetails').html(response);
$("#AppointmentDetails").modal();
}
});
},
uj5u.com熱心網友回復:
在您的 ajax 回應中回傳 html 資料時,您可以將您的 id 附加到 html 標簽之一中。讓我們在第一項中附加 id,即客戶:Dexter Veldez 行。假設 Client: 的 html 代碼是:
<b>Client:</b>
現在我們在這個標簽(b 標簽)中附加 id 并給它一個唯一的 id 'client-label',以便以后選擇這個標簽變得更容易:
<b id="client-label" data-id='<?php echo $id; ?>'>Client:</b>
現在在模態部分,在 Edit Appointment 按鈕中附加一個 onclick 事件,如下所示:
<a href="#" class="btn btn-info userdata" onclick="editButtonClicked();">Edit Appointment</a>
現在在頁面底部的腳本標簽內定義一個名為 editButtonClicked 的函式:
<script>
function editButtonClicked(){
var clientTag = document.getElementById("client-label");
var requiredId = clientTag.getAttribute('data-id');
//now navigate to edit page with the id
window.location.href = '/edit_appointment.php?id=' requiredId;
}
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/365881.html
標籤:javascript php 查询
