【发布时间】:2016-04-12 01:30:55
【问题描述】:
我正在尝试显示以下模式,其中正文是数据库驱动的。但是,此数据并未出现在 Bootstrap 模式中。我已经看这个太久了,看不到问题!
模态
<div class="modal fade" id="eventDetailsModal" tabindex="-1" role="dialog" aria-labelledby="memberModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="memberModalLabel">Event Details</h4>
</div>
<div class="dash">
</div>
</div>
</div>
</div>
AJAX
$('#eventDetailsModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
var modal = $(this);
var dataString = recipient;
$.ajax({
type: "GET",
url: "/getNearestPC.php",
data: {"foo": dataString},
cache: false,
success: function (data) {
console.log(data);
console.log(dataString);
console.log(recipient);
$('.dash').html(data);
},
error: function(err) {
console.log(err);
}
});
})
getNearest.php
//SQL Setup
$PC = $_GET['foo'];
<div class="modal-body center" style="background-color: #FFFFFF">
<table id="preusertable" class="table table-striped table-hover table-curved" style="width: 100%;">
<thead>
<tr>
<th style="color: #000000;">Event</th>
<th style="color: #000000;">Postcode</th>
</tr>
</thead>
<tbody>
<?php
while ($row = $sData->fetch(PDO::FETCH_ASSOC)) {
$school = $row['SchoolURL'];
$postcodeFull = $row['Postcode'];
?>
<tr>
<td style="font-size: 1.1em;"><?php echo $school ?></td>
<td style="font-size: 1.1em;"><?php echo $postcodeFull ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
模态触发器
<a data-toggle="modal" data-target="#eventDetailsModal" data-whatever="<?php echo $postcode ?>">
任何帮助都会很棒!它只显示模态标题但没有正文
【问题讨论】:
-
注意:控制台没有错误
-
你的 console.log(data); 是什么AJAX 调用后的输出?应该没什么吧?
-
@Y.Hermes 确实,什么都没有
-
您的问题是您的“php 代码”。我会快速为您重写并发布它作为可能的答案。
标签: javascript php jquery ajax twitter-bootstrap