title: database records show without refreshing the page using ajax
body: <p>I'm trying to show the database values using ajax function. When I add a new row into my database table it doesn't show the records immediately. I have to refresh my page. Then only it shows the recent log details. I think I have a problem with ajax coding. I'm newbie to ajax. Someone help me to solve my issue..</p>
  
  <pre><code>function updateDriver(event)
  {
      $(".panel a").each(function(){
          if($(this).hasClass("active"))
          $(this).removeClass("active");
          });
  
  
      $(this).addClass("active");
      ajaxObj.options.previousDriver = ajaxObj.options.data['did'];   
      ajaxObj.options.data = {'aid':'&lt;?=$agent_id?&gt;','did': event.data.did};
  
      //Ajax call for Driver Log Update;
  
      //function refreshEachMinute() {
        $("#RecentLog").html('Loading...');
  
        $.ajax({
                url: "&lt;?=LOAD_LOG?&gt;/",//The resource that delivers loc data.
                method: 'post', //data method
                dataType:'html',
                data: { aid: "&lt;?=$agent_id?&gt;", did: event.data.did },
                success: function(data)
                {
                    $('#RecentLog').html(data);
                },
                error: function()
                {
                    $('#RecentLog').html('&lt;p&gt;No Entries&lt;/p&gt;')
                }
  
        });
      //}
      //setInterval(refreshEachMinute, 200);
  
  }
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>case LOAD_LOG:
  
      if(!isset($_POST['aid']))
      die();
  
              $agent_id = $_POST['aid'];
              $driver_id = $_POST['did'];
  
              $sql = "SELECT * FROM ".TBL_DRIVER_LOG." where driver_id='$driver_id' ORDER BY id DESC";
              $log_data = asort_result_array($sql);
              $driver_log ="";
              if(count($log_data))
              foreach($log_data as $log)
              {
                  extract($log);
  
                  $ago = TimeAgo($date_of_update);                
                  echo '&lt;p&gt;
                  &lt;span&gt;'.$ago.', @ '.$average_speed.'km/hr&lt;/span&gt;&lt;br&gt;
                  &lt;span style="font-size: 13px; font-weight: normal;"&gt;'.$current_place.'&lt;/span&gt;
                  &lt;/p&gt;
                  &lt;hr class="tabhr"&gt;';
  
              }
              else
              echo "No Entries";
  
  
  
          exit();
  </code></pre>