title: Reload a function without reloading the page
body: <p>I want to callout a function without the page is reloading. 
  I know that this is possible with AJAX but i don't know how it works with calling a function. </p>
  
  <p>I want to put a timer so it will reload the function every 3 seconds, so the users doesnt need to reload the page everytime to see if there is a new message.</p>
  
  <pre><code>$object = new Messages();
  $object-&gt;ShowMessage($nick);
  </code></pre>
  
  <p>ShowMessage(); is the function that i want to call out every 3 seconds.</p>
  
  <p>Full code :</p>
  
  <pre><code>public function ShowMessage() {
  
      $st = $this-&gt;db-&gt;prepare("SELECT * FROM bericht");
      $st-&gt;execute();
      if($st-&gt;rowCount() == 0){
          echo 'There is no message jet!';
      }  
  
          foreach ($st as $bericht){
          $uid = $bericht['uid'];
  
          $nick = $this-&gt;db-&gt;prepare("SELECT * FROM users WHERE id=?");
          $nick-&gt;bindParam(1, $uid);
          $nick-&gt;execute();
  
              foreach($nick as $name) {   
  
              $image = $name['foto'];
  
          if($image == 'nophoto.jpg'){
          echo '&lt;img src="image/nophoto.jpg" width="60px" height="30px"&gt;';
  
          } else {
          echo '&lt;img src="image/'; echo $image.'"'; echo ' width="60px" height="30px"&gt;';
          }
          echo json_encode($name['name']) .': ';
          echo json_encode($bericht['message']).' &lt;br&gt; ';
  
      }
  
      }
  }
  </code></pre>