javascript - 如何通过调用产品 id 来获取模式中的详细信息来制作模式引导弹出窗口?
问题描述
我试图通过单击详细信息按钮来制作弹出模式引导程序。在模式中,当我单击详细信息按钮时,我可以使用 pdo 调用产品详细信息,我可以获得产品编号(id)。不幸的是,productnum(id)总是调用最后一行数据productnum(id)......我如何正确调用产品productnum(id)以在模态引导javascript中插入?
<?php
// Read
$per_page = 10;
if (isset($_GET["page"]))
$page = $_GET["page"];
else
$page = 1;
$start_from = ($page-1) * $per_page;
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("select * from tbl_products_a170804_pt2 LIMIT $start_from, $per_page");
$stmt->execute();
$result = $stmt->fetchAll();
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
foreach($result as $readrow) {
?>
<tr>
<td><?php echo $readrow['fld_product_num']; ?></td>
<td><?php echo $readrow['fld_product_name']; ?></td>
<td><?php echo $readrow['fld_product_price']; ?></td>
<td><?php echo $readrow['fld_product_brand']; ?></td>
<td><?php echo $readrow['fld_product_quantity']; ?></td>
<td>
<button class="btn btn-warning btn-xs openPopup" role="button" id="details" value="<?php echo $editrow['fld_product_num']; ?>" >Details</button>
<?php if($pos==="Admin" || $pos==="Supervisor" ){ ?>
<a href="products.php?edit=<?php echo $readrow['fld_product_num']; ?>" class="btn btn-success btn-xs" role="button"> Edit </a>
<a href="products.php?delete=<?php echo $readrow['fld_product_num']; ?>" onclick="return confirm('Are you sure to delete?');" class="btn btn-danger btn-xs" role="button">Delete</a>
</td>
<?php } ?>
</tr>
<?php } ?>
这是我的模态引导代码
<div id="myModal" class="modal fade" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Product Details</h3>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">× Close</button>
</div>
</div>
</div>
</div>
这是javascript ..当我点击它时,它总是给我最后一行ID
<script>
$(document).ready(function(){
$(".btn").click(function(){
$('.modal-body').load('products_details.php?pid=<?php echo $readrow['fld_product_num']; ?>',function(){
$('#myModal').modal({show:true});
});
});
});
**问题:**如何正确调用确切的产品编号以放入模态 javascript
解决方案
我已经解决了这个问题。只有我们数据-url
<button
data-href="products_details.php?pid=<?php echo $readrow['fld_product_num']; ?>"
class="btn btn-warning btn-xs" role="button">Details</button>
这是我的jQuery
<script>
$(document).ready(function(){
$(".btn").click(function(){
var dataURL = $(this).attr( "data-href" )
$('.modal-body').load(dataURL,function(){
$('#myModal').modal({show:true});
});
});
});
推荐阅读
- java - 一次防止“24”小时值(没有秒)
- nginx - 忽略一组 IP 地址的特定规则
- javascript - 如何将字符串转换为数组内的两个属性?
- ios - 获取要更新的进度视图
- html - 如何在每个字体图标下放置一个文本?
- java - 当 authorizeRequests antMatcher 未设置为根 url 时,Spring Boot OAuth2 SSO 不起作用
- java - 单元测试异步代码和没有外部可见效果的代码
- amazon-web-services - 如何为 Lambda 过滤 AWS 日志以仅查看 console.logs
- python - 如何在 Appveyor 上构建 Windows 中开始类似 Unix 的工作?
- reactjs - 读取输入字段更改时标签的值