Why does this jQuery .post fail to return a result, and how can I debug in Firebug?
<p>This script used to work fine, so I am mystified as to why it's not working now; but it uses .post in a simple php call to retrieve a data record given two keys, mndx and sndx, both of which contain valid data.   </p>

<pre><code> function fetchgenotype() {
    // here's where we use an Ajax function to fetch the allele values without reloading the page.
    // Get the index number of the genotype record to retrieve; retrieve it; populate the alleles.

    var mndx, sndx = 0;

    mndx = $('#marker').val();

    if (Study_selected) {
      sndx = $('#stylabid').val();
    } else { 
      sndx = $('#pjtlabid').val();
    }    

    // for debugging...    
    //alert('sndx='+sndx+', mndx='+mndx);

    // This is the cryptic jQuery 'magic' that fetches the genotype values when the
    // Fetch button is clicked, and displays the values fetched.

    $.post("fetchAlleles.php", {mndx: mndx, sndx: sndx},

      function(result) {

    // The .each method used on the return object is the key to displaying multiple
    // run dates, and genotype values, associated with a sample. 

    i=0;
    $.post("fetchAlleles.php", {'mndx': mndx, 'sndx': sndx},



function(result) {
    // this works for a single return value
    //$('#allele_1_1').get(0).value = result[0].allele1;
    //$('#allele_1_2').get(0).value = result[0].allele2;
    //$('#run_date1').get(0).value = result[0].run_date;

    // The .each method used on the return object is the key to displaying multiple
    // run dates, and genotype values, associated with a sample. 

    i=0;
$.each(result,function() {
  if (i==0) {
    $('#allele_1_1').val(this.allele1);
    $('#allele_1_2').val(this.allele2);
    $('#run_date1').val(this.run_date);
  } else if (i==1) {
    $('#allele_2_1').val(this.allele1);
    $('#allele_2_2').val(this.allele2);
    $('#run_date2').val(this.run_date);
  } else if (i==2) {
    $('#allele_3_1').val(this.allele1);
    $('#allele_3_2').val(this.allele2);
    $('#run_date3').val(this.run_date);
  }
  i=i+1;
    })
  }
);
      }
</code></pre>

<p>I have attempted to use Firebug to step into the code, but in the above code as soon as it steps past the .post line, it says result is undefined.</p>

<p>The relevant part of the php script is: </p>

<pre><code> $sql = "SELECT allele1, allele2, run_date FROM geno.genotypes WHERE markers_id=".$mndx." AND gsamples_id=".$sndx;

    // create array to hold results
    $obj_arr = array();
    $fetchresult = pg_exec($dbconnect, $sql);
    if ($fetchresult) {
        while ($obj = pg_fetch_object($fetchresult))
        // Add this object to our array of objects to return
        if (!array_push($obj_arr,$obj)) {
            echo("Error pushing results onto obj_arr");
            showerror(0,"Failed to connect to database",'fetchAlleles',38,"Failed in line 38");
            exit;
        }        
        // for debugging
        //print_r($obj_arr);
    } else {
        echo "(25) Failed to retrieve results.&lt;BR&gt;SQL: ".$sql."&lt;/br&gt;";
    }

    // It appears necessary to return the array as json encapsulated.
    echo json_encode($obj_arr);
</code></pre>

<p>Any help much appreciated!
--rixter</p>
