Why is this jquery ajax call not returning data from my php script?
<p>I'm new to jQuery, and have not been able to debug this ajax call in Firebug:</p>

<p>This is my ajax call:</p>

<pre><code>var styndx = $('#studylist option:selected').val();
var studyname = $('#edit_field').val();


$.post("saveStudyName.php", {'type': 'update', 'studyname':studyname, 'styndx':styndx},
    function(resultmsg) {
    $('#edit_field').val('');
    $('#savebtn').attr('disabled',true);
    refresh_studynames();
});
</code></pre>

<p>And this is the function refresh_studynames:</p>

<pre><code>function refresh_studynames()
{
  $.ajax({                                      
     url: 'getStudyNames.php',                  
     data: "",                                                             
     dataType: 'json',               
          error: function() {
            alert('Refresh of study names failed.');
          },
     success: function(data)
     {
        $data.each(data, function(val, sname) {
        $('#studylist').append( $('&lt;option&gt;&lt;/option&gt;').val(val).html(sname) )
      });
     } 
  });
}
</code></pre>

<p>Finally, this is the php script getStudyNames.php ($dbname,$dbconnect, $hostname are all populated, and $dbconnect works; the backend database is Postgres, and <a href="http://us3.php.net/manual/en/function.pg-fetch-all.php" rel="nofollow">pg_fetch_all</a> is a Postgres function in PHP that returns result as an array):</p>

<pre><code>$dbconnect = pg_pconnect("host=".$hostname." user=".$dbuser." dbname=".$dbname);    
    if (!$dbconnect)    {
        showerror(0,"Failed to connect to database",'saveStudyName',30,"username=".$dbuser.", dbname=".$dbname);
        exit;
    }

    $sql = "SELECT ST.studyindex,ST.studyabrv AS studyname
            FROM ibg_studies ST
            ORDER BY studyname";


    $fetchresult = pg_exec($dbconnect, $sql);
    if ($fetchresult) {
        $array = pg_fetch_all($fetchresult);
        echo json_encode($array);
    } else {
        $msg = "Failure! SQL="+$sql;
        echo $msg;
    }
</code></pre>

<p>Any help much appreciated....</p>
