0

単語クイズを提供する動的な Web サイトを作成するつもりでした。w3school の例をいくつか変更しましたが、うまくいきませんでした。

<?php 

?>

<script>
//var vocabid;
var ans;
function getnumber(str)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
return xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getnumber.php?q="+str,true);
xmlhttp.send();

}


function getvocab(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("vocab").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getvocab.php?q="+str,true);
xmlhttp.send();
}

function getpart(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("part").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getpart.php?q="+str,true);
xmlhttp.send();
}

function getchi(str)
{
var inner_ans
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    inner_ans=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getchi.php?q="+str,true);
xmlhttp.send();
return inner_ans;
}



function loadvocab()
{
//vocabid=Math.floor((Math.random()*2)+1);
vocabid=getnumber();
//vocabid= document.getElementById("num_result").value;
getvocab(vocabid);
getpart(document.getElementById("num_result").value);
var ans=getchi(vocabid);
//document.getElementById('number').innerHTML = document.getElementById("num_result").value;
//document.write(document.getElementById("num_box").value;);
//document.write(ans);
}
</script>
</head>


<body>
<div name="vocab" style="width:300px; top:10px ; background-color:rgb(255,0,255);display:inline-block; position:relative;">
vocab
<span id="vocab"></span>
</div>
<div name="part" style="width:100px;position:relative;background-color:rgb(255,0,255);display:inline-block;">
pt. of speech
<span id="part"></span>
</div>
<div name="chi" style="width:100px;position:relative;background-color:rgb(255,0,255);display:inline-block;">
chi
<span id="chi"></span>
</div>
<br>
<div name="ans_box" style="width:100px;position:relative;background-color:rgb(255,0,255);display:inline-block;top:100px;">
<form name="ans">
<input type="text" name="ans_text">
</form>
<span id="number"></span>
</div>
<div name="check" style="width:300px;left:10px; top:100px ; background-color:rgb(255,0,255);display:inline-block; position:relative;" onclick="check_vocab(document.ans.ans_text.value)">
check
<span id="check"></span>
</div>
<font  id="num"></font>
<div name="next" style="width:100px;left:10px;position:relative;background-color:rgb(255,0,255);display:inline-block;top:100px; " onclick="loadvocab();">
next
</div>
<div  style="width:100px;left:10px;position:relative;background-color:rgb(255,0,255);display:inline-block;top:100px;">
<form name="result">
<span id="txtHint"></span>
<input type="button" onclick=" getpart(1);">
<input type="button" onclick=" getvocab(1);">

<input type="button" onclick=" getchi(1);">
</form>
</div>
<div id="num_box">



</div>

「次の」div をクリックすると、多くの js 関数を通過し、アクセス ファイルから新しい単語を取得します。しかし、php で乱数を生成する最初のものは取得できませんでした。変数には「未定義」が含まれているだけです。しかし、ご覧のとおり、ボタンだけで機能します。
後で、変数をテキストボックスに入れてjsで取得しようとしましたが、データを「span」タグに戻すには2クリックかかります。
何が起こったのかを理解するのを手伝ってもらえますか、それとも私に提案をしてもらえますか?
編集:魂はユニコードをサポートしていますか?データベースにいくつかのユニコード文字があります。

4

1 に答える 1