Send and display content in a modal

0

I'm trying to show the contents of a php in a modal using a js but nothing appears I have the following JS that what it tries to do is send the AJAX variable to the PHP and the result of this would be shown in the modal

$.ajax({
  url: "table.php",
  data: {AJAX: table},
  type: "POST",
  success: function(data)
  {
    $('#modal').show();
    $('#modal-body').show().html(data);
  }
});

The content of the PHP is as follows:

    <?php

    if(isset($_POST['AJAX'])) {
        $name = $_POST['AJAX'];
    }
    echo $name;
    ?>

The content of the modal is as follows:

<div class="modal fade" id="modal">
        <div class="modal-body">                
        <!-- load content table.php -->         
        </div> 
</div>

What's wrong with me and what should I do to solve it? thanks!

    
asked by Guif If 19.11.2018 в 23:50
source

2 answers

1

It could be because you have $ ('# modal-body'). show (). html (data); but # is used to id and you have modal-body in the class

you can do: $('.modal-body').show().html(data);

or also:   <div class="modal-body" id="modal-body">

with one of the two should work

    
answered by 19.11.2018 / 23:56
source
1

Try this:

$.ajax({
  url: "table.php",
  data: {AJAX: table},
  type: "POST",
  success: function(data)
  {        
    $('#modal-body').html(data);
    $('#modal').show();
  }
});
    
answered by 19.11.2018 в 23:55