Advertisement
michaelyuen

Untitled

Jan 18th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2. /** test.php **/
  3. <!DOCTYPE html>
  4. <html> 
  5.     <head>
  6.         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  7.         <script
  8.             src="https://code.jquery.com/jquery-3.2.1.min.js"
  9.             integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  10.             crossorigin="anonymous"></script>  
  11.     </head>
  12.     <body>
  13.    
  14.         <div id="myModal" class="modal fade" role="dialog">
  15.             <div class="modal-dialog">
  16.  
  17.                 <!-- Modal content-->
  18.                 <div class="modal-content">
  19.                     <div class="modal-header">
  20.                         <button type="button" class="close" data-dismiss="modal">&times;</button>
  21.                         <h4 class="modal-title">Modal Header</h4>
  22.                     </div>
  23.                     <div class="modal-body">
  24.                         <p>Some text in the modal.</p>
  25.                     </div>
  26.                     <div class="modal-footer">
  27.                         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  28.                     </div>
  29.                 </div>
  30.  
  31.             </div>
  32.         </div>
  33.  
  34.         <ul>
  35.             <li>Record 1 <button class="edit" data-id="<?= '1'; ?>">Edit</button></li>
  36.             <li>Record 2 <button class="edit" data-id="<?= '2'; ?>">Edit</button></li>
  37.         </ul>
  38.         <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  39.         <script>
  40.             $('.edit').on('click', function(){
  41.                 var record_id = $(this).data('id');
  42.                 var data = {'edit_id' : record_id};
  43.                 $.ajax({
  44.                     url : "post.php",
  45.                     data : data,
  46.                     type: "POST",
  47.                     success : function(data) {
  48.                         console.log(data);
  49.                         $('#myModal .modal-body').html( data );
  50.                         $('#myModal').modal('show');
  51.                     }
  52.                 });
  53.             })
  54.         </script>
  55.     </body>
  56. </html>
  57.  
  58. <?php
  59. /** post.php **/
  60. <?php
  61.     if (isset($_POST['edit_id'])) {
  62.         // process your data and echo result
  63.         echo "I want to edit this id: " . $_POST['edit_id'];
  64.     }
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement