modal为每个按钮显示相同的信息

时间:2017-11-11 13:53:55

标签: javascript php html modal-dialog

我的代码正在运行,但模式显示每个按钮的相同信息。我每次都要刷新页面以获取其他按钮的信息。

有脚本和模态代码
这里的id是从数据库中获取的产品。我是新手,仍然在攻读我的学位。

 <script>
     function detailsmodal(id)
     {
         var data = {"id":id};
         jQuery.ajax({
             url : <?=BASEURL;?>+'/includes/detailmodal.php',
             method : "POST",
             data : data,
             success : function(data)
     {
         jQuery('body').append(data);
         jQuery('#details-modal').modal('toggle');
     },
             error  :function()
                {alert("something went wrong");}
         });

     }
 </script>




<?php ob_start(); ?>
 <div class="container">
     <div class="modal fade" id="details-modal" role="dialog" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true" >
         <div class="modal-dialog">
             <div class="modal-content">
                 <div class="modal-header">
                     <button type="button" class="close" data-dismiss="modal">&times;</button>  
                     <h4 class="modal-title text-center"><?= $product['title'];?></h4>
                     </div>
                 <div class="modal-body">
                     <div class="container-fluid">
                         <div class="row">
                             <div class="col-sm-6">
                                 <img src="<?= $product['image'];?>" alt="<?= $product['title'];?>" class="details img-responsive"/>
                             </div>
                             <div class="col-sm-6">
                                 <h4>Details</h4>
                                 <p><?= $product['description'];?></p><hr>
                                 <p>Price:&#8377 <?= $product['price'];?> </p>
                                 <p>Brand: <?= $brand['brand'];?></p>
                                 </div>

                     </div>
                 </div>
             </div>
                 <div class="modal-footer">
                     <button class="btn btn-default" data-dismiss="modal">Close</button>
                     <button class="btn btn-warning" type="sumbit" class="glyphicon glyphicon-shopping-cart">Add to cart</button>
                 </div>
         </div>

     </div>
 </div>
 </div>

0 个答案:

没有答案