title: Correct way of calling AJAX to fetch from database
body: <p>I am currently learning how to use AJAX and from what I can see online, the most common way of fetching data from a database is calling an AJAX function on delay loop of about 1 or 2 seconds. This seems a bit, untidy and make-do approach, not to mention putting a heavy load on the client side if a large application. </p>
  
  <p>Therefore, my question is what is the correct way of making an AJAX call to fetch data from a database? (that will update automatically) </p>
  
  <p>Thank you for your help. </p>
  
  <p>Example of an AJAX function on a delay loop:</p>
  
  <pre><code>var my_delay = 1000;     
  $(function() {
      callAjax();
  });      
  function callAjax() {
        $.ajax({    //create an ajax request to load_page.php
          type: "GET",
          url: "display.php",             
          dataType: "html",   //expect html to be returned                
          success: function(response){                    
              $("#responsecontainer").html(response); 
              setTimeout(callAjax, my_delay);
          }
      })
  };
  </code></pre>