このスクリプトは以前は正常に機能していたので、なぜ今は機能しないのか不思議です。ただし、単純な php 呼び出しで .post を使用して、mndx と sndx の 2 つのキーが指定されたデータ レコードを取得します。どちらにも有効なデータが含まれています。
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;
})
}
);
}
Firebug を使用してコードにステップインしようとしましたが、上記のコードでは、.post 行を通過するとすぐに結果が未定義であると表示されます。
PHPスクリプトの関連部分は次のとおりです。
$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.<BR>SQL: ".$sql."</br>";
}
// It appears necessary to return the array as json encapsulated.
echo json_encode($obj_arr);
どんな助けでも大歓迎です!--リクスター