title: jQuery AJAX referencing $(this) within success function
body: <p>I have a voting system which sends an id of the clicked item to a PHP script, the PHP updates the database and echos back the new vote counts via an JSON encoded array.</p>
  
  <p>This is the jQuery:</p>
  
  <pre><code>$(".vote_up").click(function(){
      var id = this.id;
      var vote = $(this).attr("class");
      var data = "id=" + id + "&amp;vote=" + vote;
      $.ajax
          ({
              type: "POST",
              url: "vote.php",
              data: data,
              cache: false,
              success: function(data)
              {
                  for(var x in data) {
                           $(".votes_up").find(id).html(data[x].vote_up);
                           $(".votes_down").find(id).html(data[x].vote_down);
                  }
              }
      });
  });
  </code></pre>
  
  <p>So when i construct the item in the first place, i take the record ID in the database and set it as the items ID. So what i'm trying to do is reference the exact item that was clicked and set it's HTML to the data thats coming back from the PHP. I've checked in Firebug and I'm getting correct data back but the count of votes isnt changing. Any ideas?</p>
  
  <p>This is the PHP for reference:</p>
  
  <pre><code>$query = "SELECT vote_up, vote_down FROM posts WHERE id = '".$id."'";
  $result1 = mysql_query($query);
  $output = Array();
  while ($row = mysql_fetch_array($result1)){
      $output[] = Array(
          "vote_up" =&gt; $row['vote_up'],
          "vote_down" =&gt; $row['vote_down'],
      );
  }
  echo json_encode($output);
  </code></pre>