【问题标题】:Pass variable to jquery将变量传递给jquery
【发布时间】:2014-12-02 08:29:31
【问题描述】:

我的目标是在模式中打开带有 ID 的循环 $viewhh 中链接的详细信息。我已经通过 jquery 等尝试了很多不同的方法,但都无法正常工作。只是调用页面就可以了,但尝试加载模式对我来说是徒劳的。

<div class="row">
             <div class="col-md-12">
                <p><a class="btn btn-default" href="add_praise.php" role="button">Add a Praise</a></p>
                <h2>Praises</h2>
                <p><?php
                    $query = "SELECT praise.id, praise.title, praise.description, praise.created, member.username FROM praise INNER JOIN member ON praise.member_id=member.id ORDER BY praise.created desc;";
                    $stmt = $db->query($query);
                    printf('<table class="table">');
                    printf('<thead><tr><th>Title</th><th>Posted By</th><th>Posted</th></tr></thead>');
                    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                        $created = date('m-d-Y', strtotime($row['created']));
                        $viewhh = '<a href="view_praise.php?id=' .
                                urlencode($row["id"]) . '">' . ($row["title"]) . '</a>';
                        printf("<tbody><tr><td> %s </td> <td> %s </td><td> %s </td><td> %s </td></tr></tbody>", $viewhh, htmlentities($row["username"]), $created, $viewbutton);
                        printf("</table");
                    }
                    ?>   </p>

            </div>

这是被调用的页面

<?php
$praiseid = urldecode($_GET['id']);
$sth = $db->prepare("select * from praise where id = '$praiseid'");
$sth->execute();
            $result = $sth->fetch(PDO::FETCH_ASSOC);
            $title = $result['title'];
                    $description= $result['description'];


            ?>  
<div class="container">
    <!-- Example row of columns -->
    <div class="row">
        <div class="col-md-4">

            <h2><?php echo $title;  ?></h2>
            <div><?php echo $description;  ?></div>

        </div>
</div>

我已经尝试添加这个,但现在只获得第一条记录。

<script>
         $(function () { 

            $("#loadpraise").colorbox({ iframe: true, width: "90%", height: "90%", closeButton: false });

            $("#events").colorbox({
                onOpen: function () { alert("Colorbox onOpen"); },
                onLoad: function () { alert("Colorbox onLoad"); },
                onComplete: function () { alert("Colorbox onComplete"); },
                onCleanup: function () { alert("Colorbox onCleanup"); },
                onClosed: function () { alert("Colorbox onClosed"); }
            });

            $("#childForm").colorbox({ closeButton: false, onClosed: function () { alert($.colorbox.popupResult) } });
        });
     </script>

【问题讨论】:

  • 确切的问题是什么?
  • js代码在哪里?
  • 这看起来是terrifyingly insecure。您确定您的用户参数是properly escaped 吗?使用 PDO 时,请务必使用prepared statements 以避免手动转义或处理引用问题。
  • 我现在只关注 jquery modal,而不是 mysql 安全性。

标签: php jquery mysql pdo modal-dialog


【解决方案1】:

我使用 BootStrap 3 modal 让它工作。

调用记录的链接:刚刚添加了data-toggle="modal"和data-target="#myModal"

$viewpraise = '<a data-toggle="modal" href="view_praise.php?id=' . urlencode($row["id"]) . '" data-target="#myModal">' . ($row["title"]) . '</a>';

在同一页面上包含远程调用的模式。远程页面被加载到“modal-content”div中。

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div> <!-- /.modal-content -->
    </div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->

然后在调用的页面上添加其余的模态内容:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Remote file for Bootstrap Modal</title>  
  <script>

   $('body').on('hidden.bs.modal', '.modal', function () {
        $(this).removeData('bs.modal');
      });</script>

</head>
<body>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Modal title</h4>
            </div>          <!-- /modal-header -->
            <div class="modal-body">
             <h2><?php echo $title;  ?></h2>
            <div><?php echo $description;  ?></div>
            </div>          <!-- /modal-body -->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!--                <button type="button" class="btn btn-primary">Save changes</button>-->
            </div>          <!-- /modal-footer -->
</body>
</html>

【讨论】:

    猜你喜欢
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 2011-01-18
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多