title: auto refresh ajax div running on php page
body: <p>Please see my code below. I want to auto refresh a <code>div</code> on a php page. I tried to refresh through javascript and html header, but it is slowly slowing down my computer. </p>
  
  <p>page2.php</p>
  
  <pre><code>&lt;?php
  
  if($_GET['type']!='ajax'){
      include 'header.php';
      echo "&lt;div id='main-content'&gt;";
  }
  ?&gt;
  Itm 1&lt;/br&gt;
  Itm 2
  
  &lt;img class="ajax-loader" src="ajax-loader.gif" alt="loading..." /&gt;
  
  &lt;?php
  if($_GET['type']!='ajax'){
      echo "&lt;/div&gt;";
      include 'footer.php';
  }?&gt;
  </code></pre>
  
  <p>app.js</p>
  
  <pre><code>$.cergis = $.cergis || {};
  $.cergis.loadContent = function () {
      $('.ajax-loader').show();
       $.ajax({
           url: pageUrl + '?type=ajax',
          success: function (data) {
              $('#main-content').html(data);
              // hide ajax loader
              $('.ajax-loader').hide();
  
    }
      });
      if (pageUrl != window.location) {
          window.history.pushState({ path: pageUrl }, '', pageUrl);
      }
  }
  $.cergis.backForwardButtons = function () {
      $(window).on('popstate', function () {
          $.ajax({
              url: location.pathname + '?type=ajax',
              success: function (data) {
                  $('#main-content').html(data);
              }
          });
      });
  }
  $("a").on('click', function (e) {
      pageUrl = $(this).attr('href');
      $.cergis.loadContent();
      e.preventDefault();
  });
  $.cergis.backForwardButtons();
  </code></pre>
  
  <p>i have tried different variation but no luck. please help me.</p>
  
  <p>thanks.</p>
  
  <p>app.js changed...</p>
  
  <pre><code>function myTimer() {
    $('.ajax-loader').show();
    $.ajax({
        url: pageUrl + '?type=ajax',
        success: function (data) {
            $('#main-content').html(data);
            // hide ajax loader
            $('.ajax-loader').hide();
          }
    });
  </code></pre>
  
  <p>}</p>
  
  <pre><code>setInterval(function(){myTimer()}, 1000);
  </code></pre>