如何解决将带有键的PHP变量传递给Bootstrap Modal
问题:
我想从单击的td中获取reserveid进入我的Bootstrap模式。
JS代码:
$('#reservationtable tbody td').on('click',function () {
if($(this).hasClass("reserved") || $(this).hasClass("reserved-right")){
var reservationid = $(this).attr('id');
$.ajax({
cache: false,type: 'POST',url: 'abfragereservierung.PHP',data: 'reservationid='+reservationid,success: function(data)
{
$('#abfrageresrvierung').show();
}
});
}
});
<td class="reserved" data-id="'. $counter['1']->reservationid .'">
<td class="reserved" data-id="'. $counter['2']->reservationid .'">
<td class="reserved" data-id="'. $counter['3']->reservationid .'">
在$ counter变量中,每个键(1,2,3)都有一个预留类型的对象
引导程序模式:
<?PHP
session_start();
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/User.PHP");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/ReservierungsController.PHP");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/UserController.PHP");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/Reservierung.PHP");
$resController = new ReservierungsController();
//PLACE WHERE I WANT TO GET THE RESERVATIONID
?>
<div class="modal fade" id="abfragereservierung" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
.....
更新:
现在,我看到其中包含正确的Reservationid的POST请求。但是我不能通过$ _POST ['reservationid']
使用它MODAL:
<?PHP
session_start();
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/User.PHP");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/ReservierungsController.PHP");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Controllers/UserController.PHP");
require_once("C:/xampp/htdocs/platzverwaltungssystemprotoyp/app/Models/Reservierung.PHP");
$userController = new UserController();
$resController = new ReservierungsController();
if($_POST['reservationid'] != ""){
$reservierung = $resController->getReservierungFromId($_POST['reservationid']);
}
?>
<form method="post">
<div class="modal fade" id="abfragereservierung" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Reservierung Nr. <?PHP echo $reservierung->reservationid ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h6>Daten</h6>
<div id="reservationdata">
<table class="table table-hover">
<tbody>
<tr>
<th>Name</th>
<td><p><?PHP echo $userController->getUserFromId($_POST['reservationid'])->nachname ?></p></td>
</tr>
<tr>
<th>Platz</th>
<td><p><?PHP echo $reservierung->tenniscourts_tenniscourtid ?></p></td>
</tr>
<tr>
<th>Datum</th>
<td><p><?PHP echo $reservierung->reservierung_am ?></p></td>
</tr>
<tr>
<th>Uhrzeit von</th>
<td><p><?PHP echo $reservierung->reservierungsanfang ?></p></td>
</tr>
<tr>
<th>Uhrzeit bis</th>
<td><p><?PHP echo $reservierung->reservierungsende ?></p></td>
</tr>
<tr>
<th>Bemerkung</th>
<td><p><?PHP echo $reservierung->bemerkung ?></p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Abbrechen</button>
<button class="btn btn-warning" type="submit" name="submit" id="submit" value="submit">Reservierung stornieren</button>
</div>
</div>
</div>
</div>
</form>
解决方法
应为var reservationid = $(this).attr('data-id');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。