jquery, php and ajax - Attempting to alert my JSON created with PHP and AJAX it my page.

jquery, php and ajax - Attempting to alert my JSON created with PHP and AJAX it my page.

hello all,
   HTML Code:

  1. <script type="application/javascript">
  2.     $(document).ready(function() {
  3.         $("#addlivestock").validator();
  4.         
  5.         $.getJSON(
  6.             "get_location.php",
  7.             function(data)
  8.             {
  9.                 alert(data.location); //alerts undefined
  10.                 /*for (var i = 0; i < data.length; i++) //attempt to loop through JSON and add the results to a select
  11.                 {
  12.                     
  13.                 }*/
  14.             }
  15.         );
  16.     
  17.     }); 
  18. </script>

PHP Code:

  1. <?php
  2.     require_once 'MDB2.php';
  3.    
  4.     $dsn = 'mysqli://***:***@localhost/lsms';
  5.     $options = array(
  6.         'debug' => 2,
  7.         'result_buffering' => false,
  8.     );
  9.    
  10.     $mdb2 =& MDB2::factory($dsn, $options);
  11.     if (PEAR::isError($mdb2)) {
  12.         die($mdb2->getMessage());
  13.     }
  14.    
  15.     // Proceed with a query...
  16.     $res =& $mdb2->query('SELECT * FROM location');
  17.    
  18.     // Always check that result is not an error
  19.     if (PEAR::isError($res)) {
  20.         die($res->getMessage());
  21.     }
  22.    
  23.     //Create a location array to store the results pulled from the database.
  24.     $location = $res->fetchAll(MDB2_FETCHMODE_OBJECT);
  25.    
  26.     echo json_encode($location);
  27.    
  28.     $mdb2->disconnect();
  29. ?>

The php code works as expected and echos out:
[{"id":"3","location":"Chicken Pen 1"},{"id":"4","location":"Chicken Pen 2"},{"id":"5","location":"Chicken Pen 3"},{"id":"6","location":"Chicken Pen 4"}]


alert(data.id); alerts undefined.  I'm attempting to make sense of this issue and can't figure out why Its not alerting the locations. I checked the response of get_location.php in firebug and the JSON data is there. Any help is greatly appreciate!

Thanks,
     Rich