简体   繁体   English

PHP jQuery将数据加载到引导模态框

[英]PHP jQuery load data into bootstrap modal box

I need to load dynamic data into bootstrap modal box. 我需要将动态数据加载到引导模式框中。

JS: 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 file : PHP文件:

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

and print data into modalbox div with class="something" . 并使用class="something"数据打印到modalbox div this method true worked and print all php array result. 此方法真正有效并打印所有php数组结果。

now I need to work with php array aftar load data into modalbox(work with php class, secure data, ....). 现在我需要用PHP阵列aftar负载数据工作纳入modalbox(与PHP类,安全的数据,....工作)。 I mean is: load php data into modalbox (ie : json ) not print result into modalbox. 我的意思是: 负载 PHP数据到modalbox(即: json不打印结果到modalbox。

how do can I generate this? 我该如何生成呢?

Hi man here an example: http://jsfiddle.net/leojavier/kwh2n00v/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 JS

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

I hope this helps... http://jsfiddle.net/leojavier/kwh2n00v/1/ 希望对您有所帮助... http://jsfiddle.net/leojavier/kwh2n00v/1/

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

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