title: calling php from js (w/ ajax)
body: <p>I'm building a basic forum where every post contains some text, first and last name, and the date the message was written.
  I'd like to have the board update with AJAX constantly, and to add new messages on the fly as they are written.
  I have a file, <code>getlatest.php?date=...</code> that retrieves all messages from the date in the <code>$_GET</code> till <code>NOW()</code>.
  It returns the data as an array of objects. Lastly, I JSON-encode the data.
  I call this function from some AJAX code, like so:</p>
  
  <pre><code>
   setInterval("update()", 5000);
                  function update(){
                      $.get("getlatest.php", {
                          date: "2009-06-23_16:22:12" //this is just a date I
                                                      //entered for testing
                      }, function(forumdata){
                                             //do something with forumdata here?
                      }, "json");
                  }
  </code></pre>
  
  <p>Now I have the data within <code>forumdata</code>, as in <code>forumdata[0].first_name</code> ect.</p>
  
  <p>I would like to now use PHP to display the comment, like so:</p>
  
  <pre><code>$forumdata = json_decode(forumdata);
  foreach ($forumdata as $value)
  {
      $newpost = new Post($value); // Post being some class that gets the data from 
                                   // $value and converts it to HTML + CSS
      $newpost-&gt;displayPost();     // some function that echo's the HTML
  }
  </code></pre>
  
  <p>I realize what I'm trying to accomplish here is slightly unfeasible, since PHP is a server-side language, and the calculations are at this point client-side, but is there some way (maybe through AJAX?) that I could use PHP to manage the data, once I retrieve it through javascript?</p>
  
  <p>My main reason for wanting to do this is my total lack of knowledge in javascript, so any alternatives for translating the <code>forumdata</code> variable into blocks of HTML and CSS are also great for me.</p>