简体   繁体   中英

PHP jQuery load data into bootstrap modal box

I need to load dynamic data into bootstrap modal box.

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 :

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" . this method true worked and print all php array result.

now I need to work with php array aftar load data into modalbox(work with php class, secure data, ....). I mean is: load php data into modalbox (ie : json ) not print result into modalbox.

how do can I generate this?

Hi man here an example: 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');
    //--------------------------------------
})

I hope this helps... http://jsfiddle.net/leojavier/kwh2n00v/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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