title: reload the page using ajax in order to create a live chat
body: <p>I have this code:</p>
  
  <pre><code>&lt;?php require_once("config.inc.php"); ?&gt;
  &lt;?
  ob_start();
  session_start();
  if(isset($_SESSION['myusername'])) {
  // do nothing here
  } else { ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Live chat&lt;/title&gt;
  &lt;/head&gt;
  &lt;body bgcolor="#000000"&gt;
  &lt;font color="white" size="+3"&gt;&lt;b&gt;You are not logged in! &lt;br /&gt;
  Log in and start chatting!&lt;/b&gt;&lt;/font&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php exit(); }
  ob_flush();
  ?&gt;
  
  
  
  
  
  
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;meta name="description" content="&lt;?php echo $meta_description ?&gt;" /&gt;
  &lt;meta name="keywords" content="&lt;?php echo $meta_keywords ?&gt;" /&gt;
  &lt;title&gt;&lt;?php echo $site_name; ?&gt; | Live chat&lt;/title&gt;
  &lt;link rel="icon" type="image/gif" href="favicon.png" &gt;
  &lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;
  &lt;style&gt;
      body { margin:0;padding:0;  background-image:url(images/background.jpg);  }
  &lt;/style&gt;
  &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  $(document).ready(function() {
           $("#lolmesazhet").load("mesazhetnechat.php");
     var refreshId = setInterval(function() {
        $("#lolmesazhet").load("mesazhetnechat.php");
     }, 1000);
     $.ajaxSetup({ cache: false });
  });
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"&gt;
    &lt;tr&gt;
      &lt;td width="500px" bgcolor="#000000" &gt;
      &lt;?php include 'headerchat.inc.php'; ?&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td width="500px"  align="left" valign="top" style="padding:20px 5px 20px;"&gt;
  &lt;?php
  if($_POST['submit654']) {
  
  $result128 = mysqli_query($con,"SELECT id FROM users WHERE email = '$_SESSION[myusername]'");
  $row128 = mysqli_fetch_array($result128);
  
  date_default_timezone_set("Europe/Tirane");
  $todaydate3 = date("Y-m-d H:i:s");
  
  mysqli_query($con,"INSERT INTO chat (id, derguesi, dhoma, mesazhi, ora) VALUES (NULL, '$row128[id]', 'Main room', '$_POST[mesazhi]', '$todaydate3')");
  }
  ?&gt;
  &lt;table width="470px" border="0" cellspacing="0" cellpadding="0"&gt;
    &lt;tr&gt;
      &lt;td height="50px" valign="middle" colspan="2" style="border-bottom:1px solid #FFFFFF;"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td width="320" height="339px" valign="top" style="padding:3px;"&gt;
  &lt;div style="width:320px; height:339px; overflow-y:auto;"&gt;
  &lt;?php
  $result73 = mysqli_query($con,"SELECT * FROM chat WHERE dhoma = 'Main room' ORDER BY id DESC");
  while($row73 = mysqli_fetch_array($result73))
    {
  
  $result127 = mysqli_query($con,"SELECT username FROM users WHERE id = '$row73[derguesi]'");
  $row127 = mysqli_fetch_array($result127);
  ?&gt;
  &lt;table width="320px" border="0" cellspacing="0" cellpadding="0"&gt;
    &lt;tr&gt;
      &lt;td width="150" align="left"&gt;&lt;font color="white" size="4"&gt;&lt;b&gt;&lt;?php echo $row127['username']; ?&gt;&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
      &lt;td width="170" align="right"&gt;&lt;?php echo $row73['ora']; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td colspan="2"&gt;
  &lt;font color="white"&gt;&lt;?php echo $row73['mesazhi']; ?&gt;&lt;/font&gt;
  &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;?php } ?&gt;
  &lt;/div&gt;
  &lt;/td&gt;
      &lt;td width="150" height="450px" rowspan="2" valign="top" style=" padding:3px;  border-left:1px solid #FFFFFF;"&gt;
      &lt;div style="width:150px; height:450px; overflow-y:auto;"&gt;
      &lt;font color="#FFFFFF" size="+2"&gt;&lt;b&gt;Online users:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;
      &lt;?php
          $result = mysqli_query($con,"SELECT username FROM users WHERE verifikuar='po' AND online = 'po'");
      while($row = mysqli_fetch_array($result))
            { ?&gt;
                  &lt;font color="#FFFFFF"&gt;&lt;b&gt;&lt;?php echo $row['username']; ?&gt;&lt;/b&gt;&lt;/font&gt;  &lt;br /&gt;
            &lt;?php }
          ?&gt;
      &lt;/div&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td height="50px" valign="middle" style="border-top:1px solid #FFFFFF; padding:3px; border-right:1px solid #FFFFFF;"&gt;
  &lt;form action="" method="post" name="comesazh"&gt;
  &lt;textarea name="mesazhi" cols="35" rows="4" required="required"&gt;&lt;/textarea&gt;
  &lt;br /&gt;&lt;input type="submit" name="submit654" id="submit654" value="Send" style="border-radius:0px; border-size:1px; border-style:solid; border-color:#ffffff; border-width:thin; background-color:#000000; color:#ffffff; height:26px; width:60px;  font-size:16px;" /&gt;
  &lt;/form&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I would like to know if it is possible to reload that page using ajax in order to create a live chat and if yes, how to do it.<br>
  I tried many ways like reloading just a part of it using <code>$.load</code> function but it does not work. Then I tried to <code>$.load</code> all the page, but still did not work. After a lot of silly efforts, I gave up.</p>