简体   繁体   English

单击按钮-打开带有动态详细信息的模式弹出窗口

[英]on button click - open modal popup with dynamic details

Have 3 buttons for each size of a product 每个产品尺寸都有3个按钮

<table width="100%" style="font-family:Calibri, Arial; margin-top:10px">
                <?php
                    while($prod_row = mysql_fetch_array($prod_result))
                    {
                        if($prod_row['name']<>"" && $prod_row['price']<>0)
                        {
                ?>
                <tr>
                    <td style="padding-left:30px"><?php if($cat == "Design"){echo "Rs. ".$prod_row['price'];}else{echo $prod_row['name']." (Rs. ".$prod_row['price'].")";} ?></td>
                    <td style="text-align:center; vertical-align:middle" id="buy_data"><a role="button" class="btn btn-primary" data-toggle="modal" data-target="<?php if($_SESSION['logged_in']){echo '#buy_product';}else{echo '#login_buy';} ?>" id="<?php echo $prod_row['id']; ?>" name="<?php echo $prod_row['price']; ?>" title="<?php echo $prod_row['name']; ?>">Buy</a></td>
                </tr>
                <?php 
                        }//if closes
                    }//while closes 
                ?>
            </table>

On clicking the link, a modal popup should open showing some details of the clicked size 点击链接后,应该会弹出一个模式弹出窗口,其中显示了点击大小的一些详细信息

what i am doing is: 我在做什么是:

  1. triggering an onclick event to store product details (of the clicked size) in session variables via session_product.php 触发onclick事件,以通过session_product.php在会话变量中存储(点击大小的)产品详细信息
  2. displaying the modal with required details using these session variables 使用这些会话变量显示具有所需详细信息的模态

script for onclick event onclick事件的脚本

$("#buy_data a").unbind("click").click(function(e){ 
    var productnumber = $(this).attr('id');
    var prodprice = $(this).attr('name');
    var prodsize = $(this).attr('title');
    var checkprodid = productnumber;
    $.post('session_product.php',{productid: checkprodid, productprice: prodprice, productsize: prodsize});
});

session_product.php session_product.php

<?php
session_start();
$_SESSION['productprice'] = $_POST['productprice'];
$_SESSION['productsize'] = $_POST['productsize']
?>

modal popup 模态弹出

<div id="buy_product" class="modal hide fade well" tabindex="-1" role="dialog" aria-labelledby="buy_product_label" aria-hidden="true">
    <div class="modal-body">
        <h4 id="buy_product_label"></h4>
        <p style='color:#000'>
            Thank you <b><?php echo $_SESSION['user_name']; ?></b> for showing your interest in our website. You intend to purchase Product ID - <b><?php echo $_SESSION['prod_code']; ?></b><?php if($_SESSION['cat'] == "Photograph"){ ?> of size <b><?php echo $_SESSION['productsize'];} ?></b> worth Rs. <b><?php echo $_SESSION['productprice']."-".$_SESSION['cat']; ?></b><br /><br />
        <form id="thanks_popup" action="buy_email_notification.php" method="post">
            <input style="text-align:center" class="btn btn-primary" type="submit" id="" name="buy_popup_submit" value="OK, Got it!" />
        </form>
    </div>
</div>

Problem: on clicking a link, modal popup is showing product details corresponding to previously clicked link. 问题:单击链接时,模式弹出窗口会显示与先前单击的链接相对应的产品详细信息。

Please let me know where am i going wrong and what should be the solution to it. 请让我知道我要去哪里错了,应该怎么解决。 thanks! 谢谢!

You should refresh request for popup. 您应该刷新弹出请求。 Current browser document have the old data that generated from previous request. 当前浏览器文档具有从先前请求生成的旧数据。 Why don't you get the popup through ajax call? 为什么不通过ajax调用获得弹出窗口?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM