1

The code I have is a side bar that uses javascript to appear and disappear. When a button (create group) is pressed it resets the page. I want to be able to press the button, have php do something like: and It has to not refresh the page. Here is the code:

   <header class="header">
     <div class="btn-toggle-nav" onclick="toggleNav()"></div>
     <h1 class="logobrand">DEVIE</h1>
   </header>
   <aside class="nav-sidebar">
     <ul>
       <li> <p>Friends</p> </li>
       <li>
         <button name="creategroup">Create a group</button></li>
       <?php
     foreach (getGroups($_SESSION['user-id']) as $group) {
           echo "<li> <p> ". $group ." </p> </li>";
       }
       ?>
     </ul>
   </aside>
   <?php if (isset(['creategroup'])) {
     echo "please work";
   } ?>
 </body>

Please help

Andry
  • 16,172
  • 27
  • 138
  • 246
  • Jquery comes to mind with ajax calls. What you are showing above is a 'mix' of server-side and client-side actions. Which happen at completely different times. – IncredibleHat Jul 22 '20 at 12:40
  • The button will need to invoke a javascript script which makes a AJAX call to your server. There your server does whatever logic it needs to do to add the group and then it will return, in the HTTP response, the details about the new group added. After the AJAX call is done, the same script will take care of finding a reference to the
      element and add an additional `
    • ` with the info it just got back from the server.
    – Andry Jul 22 '20 at 12:51

0 Answers0