title: AJAX change comment on table row click
body: <p>I'm currently developing a web app that demonstrates how to "sign" different words in ASL. There's a list of terms on the left, and a video and comment section on the right.</p>
  
  <p>See screenshot here: <a href="http://i917.photobucket.com/albums/ad19/brycematheson/Screen%20Shot%202015-06-16%20at%2010.05.36%20PM.png" rel="nofollow">http://i917.photobucket.com/albums/ad19/brycematheson/Screen%20Shot%202015-06-16%20at%2010.05.36%20PM.png</a></p>
  
  <p>I'm struggling to get the comments to change using AJAX whenever a new term is clicked. Currently, the comments stay the same as new terms are selected. How would I go about using AJAX to change the comment section to update when a new term is selected?</p>
  
  <p>My comment section looks like so. Updating the <code>$id_post=3</code> section in PHP will change the comment to match the comments with that ID in the database, so that's not an issue, I just need it to do it on the fly.</p>
  
  <p>Here is my comment code in my index.php page:</p>
  
  <pre><code>&lt;?php 
                  // Connect to the database
                  require_once('models/db-settings.php'); 
                  $id_post = '$_POST['rowID']; //the post or the page id
                  ?&gt;
                  &lt;div class="cmt-container"&gt;
                      &lt;?php 
                      $sql = mysqli_query($mysqli, "SELECT * FROM comments WHERE id_post = '$id_post' ORDER BY id ASC") or die(mysqli_error($mysqli));
                      while($affcom = mysqli_fetch_array($sql,MYSQLI_ASSOC)) {
                          $id = $affcom['id'];
                          $name = $affcom['name'];
                          $email = $affcom['email'];
                          $comment = $affcom['comment'];
                          $date = $affcom['date'];
  
                          // Get gravatar Image 
                          // https://fr.gravatar.com/site/implement/images/php/
                          $default = "mm";
                          $size = 35;
                          $grav_url = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?d=".$default."&amp;s=".$size;
  
                      ?&gt;
                      &lt;div class="cmt-cnt"&gt;
                          &lt;img src="&lt;?php echo $grav_url; ?&gt;" /&gt;
                          &lt;div class="thecom"&gt;
                              &lt;h5&gt;&lt;?php echo ucfirst($name); ?&gt;&lt;/h5&gt;&lt;span data-utime="1371248446" class="com-dt"&gt;&lt;?php echo $date; ?&gt;&lt;/span&gt;
                              &lt;br/&gt;
                              &lt;p&gt;
                                  &lt;?php echo $comment; ?&gt;
                              &lt;/p&gt;
                              &lt;div style="float:right;"&gt;&lt;span class="action"&gt;&lt;a href="#" id="&lt;?php echo $id; ?&gt;" class="delete" title="Delete"&gt;X&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;&lt;!-- end "cmt-cnt" --&gt;
                      &lt;?php } ?&gt;
  
  
                      &lt;div class="new-com-bt"&gt;
                          &lt;span&gt;Write a comment ...&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;div class="new-com-cnt"&gt;
                          &lt;textarea class="the-new-com"&gt;&lt;/textarea&gt;
                          &lt;div class="bt-add-com"&gt;Post comment&lt;/div&gt;
                          &lt;div class="bt-cancel-com"&gt;Cancel&lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="clearfix"&gt;&lt;/div&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>And my Javascript:</p>
  
  <pre><code> $('#matrix tr').click(function (event) {
        var rowID = ($(this).attr('id')); //trying to alert id of the clicked row          
      $(function(){
              e.preventDefault();
              $.ajax({
                  type: 'POST',
                  url: 'index.php', 
                  data: rowID,
                  success: function(msg) {
                  }
             });
         });
      });
  </code></pre>
  
  <p>What am I doing wrong? Am I missing something?</p>
  
  <p>Thanks in advance.</p>