私はこれまでAjaxを使ったことがなく、少し遊んでそれを学ぼうとしています(同僚が提案したように、jqueryに行く前に何かを理解するのが好きです)。ラジオボタン(DBから取得したオプション)で始まるページがあります。これを選択すると、新しいラジオボタン(DBから取得したオプション)がトリガーされます。最初の「選択」の結果を表示することから始めましたが、ラジオボタンから何かを選択しても何も起こらず、その理由がよくわかりません。なぜこれが私が期待することをしないのか誰かが私に言うことができれば私はそれが大好きです。
前もって感謝します
メインページ:
<html>
<head>
<script>
function showGlycopeptides(str)
{
var xmlhttp;
if (str=="")
{
document.getElementById("txtField").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtField").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getglycopeptides.php?q="+str,true);
xmlhttp.send();
}
</script>
<title>LeidenGlycoPeptide DataBase</title>
</head>
<body>
<h1>Welcome to the LeidenGlycoPeptide DataBase</h1>
<?php
$link = mysql_connect("localhost","reader","") or die (mysql_error());
mysql_select_db('leidenGlycoPeptide') or die ();
$query = 'select protein from glycoPeptide';
$result = mysql_query($query);
mysql_close($link);
?>
<form>
<p>Select glycopeptide to search for (interactive dialog)</p>
<?php
echo"<select name=\"prec\" onchange=\"showGlycopeptides(this.value)\">";
echo"<option value=\"\">select glycoprotein</option>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
echo"<option value=\"$col_value\">$col_value</option>";
}
}
echo"</select>";
?>
</form>
<br>
<div id="txtField"><b>Text field</b></div>
</body>
getglycophenols.php:
<html>
<head>
<title>glyco</title>
</head>
<body>
<?php
$q=$_GET["q"];
$link = mysql_connect("localhost","reader","") or die (mysql_error());
mysql_select_db("leidenGlycoPeptide",$link) or die();
$query = "select glycoType from run,glycoPeptide where run.id = glycoPeptide.id and glycoPeptide.protein like '".$q."'";
echo "<select name=\"type\" onchange=\"foo\">";
echo "<option value=\"\">select glycosylation</option>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
foreach ($row as $col_value)
{
echo"<option value=\"$col_value\">$col_value</option>";
}
}
echo "</select>";
$result = mysql_query($query);
mysql_close($link);
?>
</body>
</html>
----編集済み----
コードは、(他の人のための)例として役立つように編集されました。