PHP jQuery将数据加载到bootstrap模式框中

时间:2015-08-31 15:24:38

标签: javascript php jquery mysql twitter-bootstrap

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

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);
}

打印数据到div的modalbox class="something"。这个方法真的有效,打印所有php数组结果。

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

我该如何生成这个?

1 个答案:

答案 0 :(得分:-1)

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

expression

JS

<!-- 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>

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