【问题标题】:PHP jQuery load data into bootstrap modal boxPHP jQuery 将数据加载到引导模式框
【发布时间】:2015-11-25 16:36:33
【问题描述】:

我需要将动态数据加载到引导模式框中。

JS:

$(function() {

    $('.push').click(function() {
        var id = $(this).attr('id');

        $.ajax({
            type: 'post',
            url: '../controller/booksdetails.php', // in here you should put your query 
            data: 'cmid=' + id, // here you pass your id via ajax .
            // in php you should use $_POST['post_id'] to get this value 
            success: function(r) {
                // now you can show output in your modal 
                $('#cm').modal({
                        backdrop: 'static',
                        keyboard: false
                    }) // put your modal id 
                $('.something').show().html(r);
            }
        });


    });

});

PHP 文件:

if(isset($_POST['cmid'])){
$DB =  mysqli::f("SELECT * FROM " . BOOKS . " WHERE id = ?",filter_var($_POST['cmid'], FILTER_VALIDATE_INT));
print_r($DB);
}

打印数据到模态框divclass="something"。此方法真正有效,并且 打印 所有 php 数组结果。

现在我需要使用 php 数组 aftar 将数据加载到 modalbox(使用 php 类、安全数据……)。我的意思是:load php 数据到 modalbox(即:json不打印 结果到 modalbox。

我怎样才能生成这个?

【问题讨论】:

    标签: javascript php jquery mysql twitter-bootstrap


    【解决方案1】:

    你好,这里有一个例子:http://jsfiddle.net/leojavier/kwh2n00v/1/

    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary btn-lg" id="insert">
      insert data
    </button>
    
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
          </div>
          <div class="modal-body">
            ...
          </div>
          <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>
        </div>
      </div>
    </div>
    

    JS

    $('#insert').on('click', function (){
        // This should be on your AJAX Success
        var data="some dynamic data";
        $('.modal-body').html(data);
        $('#myModal').modal('show');
        //--------------------------------------
    })
    

    我希望这会有所帮助... http://jsfiddle.net/leojavier/kwh2n00v/1/

    【讨论】:

    • 你的方法很可能是我的方法!!!在您的方法中,您将所有结果打印到模态框中!我不需要这个。
    • 你能把这个问题说得更具体些吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    相关资源
    最近更新 更多