title: develop Chat module in php, mysql and ajax jquery
body: <p>I am trying to implement a small chat application where user can text chat with any one of the online users.
  My logic behind this is some thing like the following:</p>
  
  <pre><code> Login first.
  
   Fetch the users who are online from DB and show them as list of online users.
  
   Click on the users, then another small window is opening for text chatting.
  
   Create a form(two hidden fields- one is for sender id and another is for receiver id, one textarea and a button for submitting) for this chatting.
  
   Through jQuery, fill the value of receiver id.
  
   By session id, fill the value of sender id.
  
   After submitting the button, I call a page through ajax jquery which is responsible to insert and show the current data from DB.
  </code></pre>
  
  <p>My code for the ajaxJquery is like :
   </p>
  
  <pre><code>$(document).ready(function(){
          $('#send_btn').click(function(){
              var receiver_id = $('#hide_receiver_id').val();
              var sender_id = $('#hide_sender_id').val();
              var messagebox = $('#messagebox').val();
  
              $.ajax({
                  type:"POST",
                  url:"chat_history.php?receiver_id="+receiver_id+"&amp;sender_id="+sender_id+"&amp;message="+messagebox,
                  success:function(result){
                      $('#history').html(result);
                  }   
  
              });
              $('#messagebox').val('');
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Up to this, its working fine. But I need to autoload the <code>&lt;div id="history"&gt;&lt;/div&gt;</code> portion. For that also I am thinking to do by using <code>setInterval()</code> in jQuery. My code is like : </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    var auto_refresh = setInterval(
     function (){
      $('#history').load("chat_history.php?receiver_id=''&amp;sender_id=&lt;?php echo $_SESSION['id']?&gt;&amp;message=").fadeIn("fast");
     }, 1000); // refresh every 1000 milliseconds
  &lt;/script&gt;
  </code></pre>
  
  <p>But in this scenario, how to pass the value of <code>receiever_id</code> in <code>load()</code> which is necessary to find out the respective data from DB?
  Please let me know whether the requirement is cleared to you or not.</p>
  
  <p>Thanks in advance.</p>