Issue with JSON and return data for $.Post

Issue with JSON and return data for $.Post

Hello,

I am having a problem with json data always appearing as "false" when directly returning it to $.post

My jQuery function is the following:
  1.       //inside another function called with "page" as an argument
  2.       //this function is to repopulate form fields
  3. jQuery.post("Edit.php", {SearchFor: page}, function(data,success){
  4. alert(data);
  5.                         //should loop through the json object and assign it to the correct form fields
  6.                         $.each(data, function (i, elem) {
  7. $("input[name='"+i+"']").val(elem);
  8. });
  9. }, "json");

Edit.php generates a json string to return as follows:

  1. <?php
  2. //excluding some code
  3. $sql  = "SELECT * FROM `test` WHERE `testname` = 'Default' LIMIT 1";
  4. $result =$db->query($sql);

  5. //echo result back to $.post function
  6. echo json_encode(mysql_fetch_assoc($result));
  7. ?>
This will display as false when I alert(data); in the jQuery function.

If I explicitly return the string that json_encode(mysql_fetch_assoc($result)); creates the data appears correctly. (I have the string that json_encode outputs logged to a text file, so I know it is generating the correct json string).

Short version:

Something about the way php echo's  json_encode(mysql_fetch_assoc($result)); is causing a problem when passing the json string back to jQuery, that directly passing the string does not.
If I pass the string explicitly it works!! ie: echo '{"formtag": "Somedata"}';

Thanks for any advice the community can offer!