title: Ajax div refreshing
body: <p>I have a problem with AJAX , I cant find a good solution to refresh only my div "chatwindow" every second. I have tried many posts from stackoverflow and from google.
  Can someone help me... to make this.
  So far my code</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;?php
      include 'config.php';
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;JavaScript Chat&lt;/title&gt;
      &lt;link href="style.css" rel="stylesheet" type="text/css"/&gt;
  
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;div id="chatwindow"&gt;
              &lt;?php
                  $result = mysql_query("select * from Message");
                  while($row = mysql_fetch_array($result))
                  {
                      echo '&lt;p&gt;' . $row['username'] . " : " . $row['message'] . '&lt;/p&gt;';
                  }
              ?&gt;  
          &lt;/div&gt;
  
          &lt;div class="inputMessage"&gt;
              &lt;form method="post"&gt;
                  &lt;hr&gt;&lt;/hr&gt;
                  &lt;textarea name="message" rows="1" cols="55"&gt;&lt;/textarea&gt;&lt;br/&gt;Fill username here&lt;br/&gt;
                  &lt;input type="submit" value="verstuur" name="submit"/&gt;
                  &lt;input type="text" value="" name="username" /&gt;
              &lt;/form&gt;
          &lt;?php
              if(isset($_POST['submit'])) 
              {
                  if (!empty($_POST['username']))
                  {
                      if(!empty($_POST['message']))
                      {
                          $message =  mysql_real_escape_string(htmlentities($_POST['message']));
                          $username =  mysql_real_escape_string(htmlentities($_POST['username']));
                          $query = "INSERT INTO Message (`username`,`message`) VALUES ('".$username."','".$message."')";
                          mysql_query($query);
                      }
                      else
                      {
                           echo '&lt;script type="text/javascript"&gt;alert(\'Je kan niet niks sturen\')&lt;/script&gt;'; 
                      }
                  }
                  else
                  {
                      echo '&lt;script type="text/javascript"&gt;alert(\'Vul een gebruikresnaam in!\')&lt;/script&gt;';
                  }
              }
              ?&gt;      
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
    [1]: http://chaotix.nl/chat/ "chat"
  </code></pre>