title: How to retrieve info from database using ajax/json? (jQuery Week Calendar)
body: <p>I'm trying to adapt the following <a href="https://github.com/themouette/jquery-week-calendar/wiki" rel="nofollow noreferrer">jQuery calendar module</a> to integrate it with PHP and a MySQL database. The problem I'm having is that the code loads events as such:</p>
  
  <pre><code>  return {
       events : [
          {
             "id":1,
             "start": new Date(year, month, day, 12),
             "end": new Date(year, month, day, 13, 30),
             "title":"Lunch with Mike"
          },
          {
             "id":2,
             "start": new Date(year, month, day, 14),
             "end": new Date(year, month, day, 14, 45),
             "title":"Dev Meeting"
          },
          {
             "id":3,
             "start": new Date(year, month, day + 1, 17),
             "end": new Date(year, month, day + 1, 17, 45),
             "title":"Hair cut"
          }
       ]
    };
  </code></pre>
  
  <p>I want to change this to an AJAX query that retrieves the events from the database. But I can't figure out exactly how to do this. So far I thought of using JSON to get the information from a separate PHP page that calls the data, but how can I manipulate the data to return a proper object?</p>
  
  <p>So far I have something like this:</p>
  
  <pre><code>  $.ajax({
          type: 'POST',
          url: 'test.php',
          dataType: 'json',
          cache: false,
          success: function(result) {
              //how can I copy the results to be able to return them?
          }
      });
  </code></pre>
  
  <p>And then in test.php I have something like</p>
  
  <pre><code>    $sql = $db-&gt;query("SELECT * FROM calendar;");
  
      $results = array();
      while($row = mysql_fetch_assoc($sql))
      {
         $results[] = array(
            'id' =&gt; $row['id'],
            'start' =&gt; $row['start'],
            'end' =&gt; $row['end'],
            'title' =&gt; $row['title']
         );
      }
      echo json_encode($results);
  </code></pre>
  
  <p>Keep in mind I also have to pass the start and end values through new Date().</p>
  
  <p>Thank you for your time.</p>