jQuery.Post() - accessing the returned json object

jQuery.Post() - accessing the returned json object

Hi,

The below code posts a couple of vars to a php file which sends back a json object containing (in the test case) one object called 'faves'  with 2 variables (let's say called var1 and var2). I can't seem to access the variables after the ajax call. The result is always an 'undefined' error message. I've tried:

  1. console.log(data.var1) 
  2. console.log(data.faves.var1)
  3. console.log(var1)
All to no avail. Can anyone tell me what I'm doing wrong here? I have checked with FireBug that all the data returned is good and well-formed etc.
  1.     $(function() {
            $.post("<? echo base_url(); ?>test.php", {

  2.             id: "<?php echo $id; ?>",
  3.             action: "check", code:  '' },
                  function(data){
                      console.log(data.var1);
                  }, "json");
        }); 




many thanks,

Mike